Skip to content

Commit fbd1603

Browse files
committed
#Modification 137
1 parent e2e2907 commit fbd1603

File tree

92 files changed

+945
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+945
-211
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Java Placement Preparation DSA CRACKER SHEET 💻🦸‍♂️🐱‍👤[357/450]
1+
# Java Placement Preparation DSA CRACKER SHEET 💻🦸‍♂️🐱‍👤[390/450]
22

33
☄ This is a full fled-ged repository for learning Java Language & DSA for Placement Preparation.
44

Relevel_Test.java

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,118 @@
1-
2-
/*
3-
Problem -> Solve History Ranking
4-
5-
DUMB JERRY
6-
DUMB JERRY
7-
8-
Problem Statement
9-
10-
As usual, Jerry and Tom are fighting. Tom wants to prove that Jerry is Dumb, So he made a problem and asked jerry.
11-
12-
Given a sequence A of size N, and an operation.
13-
14-
In one operation you can pick an element either from the front or back of the Sequence and write it down and delete it from the array.
15-
Jerry has to perform the given operation until sequence A becomes empty.
16-
17-
Tom wants the written sequence to be lexicographically maximum possible by performing the given operation on sequence A.
18-
19-
Jerry can’t solve the problem on his own. So you have to help him.
20-
21-
Note:-
22-
23-
Sequence X of length N is lexicographically greater than Sequence Y of length N, if there exist such i (1<=i<=N), that Xi >Yi and for any j (1<=j<i) Xi=Yi.
24-
25-
Constraint
26-
27-
• 1 <= N <= 105
28-
• 0 <= Ai <= 109
29-
30-
• All input values are integer.
31-
32-
Input Format
33-
34-
• First-line contains N, length of the sequence A
35-
36-
• Second line contains N space-separated integers denoting the sequence A.
37-
38-
Output Format
39-
40-
• In first print the lexicographically maximum sequence made by performing operations on sequence A
41-
42-
Sample Input 1
43-
44-
3
45-
46-
3 1 2
47-
48-
Sample Output 1
49-
50-
3 2 1
51-
52-
Explanation of Sample 1
53-
54-
For test case1
55-
56-
We get sequence {3,1,2} if we
57-
Pick the element from the front of the sequence (3) and delete it from the original sequence {1,2}
58-
Pick the element from the front of the sequence (3,1) and delete it from the original sequence {2}
59-
Pick the element from the front of the sequence (3,1,2) and delete it from the original sequence {}
60-
We get sequence {3,2,1} if we
61-
Pick the element from the front of the sequence (3) and delete it from the original sequence {1,2}
62-
Pick the element from the back of the sequence (3,2) and delete it from the original sequence {1}
63-
Pick the element from the front of the sequence (3,2,1) and delete it from the original sequence {}
64-
We get sequence {2,3,1} if we
65-
Pick the element from the back of the sequence (2) and delete it from the original sequence {3,1}
66-
Pick the element from the front of the sequence (2,3) and delete it from the original sequence {1}
67-
Pick the element from the front of the sequence (2,3,1) and delete it from the original sequence {}
68-
We get sequence {2,1,3} if we
69-
Pick the element from the back of the sequence (2) and delete it from the original sequence {3,1}
70-
Pick the element from the back of the sequence (2,1) and delete it from the original sequence {3}
71-
Pick the element from the front of the sequence (2,1,3) and delete it from the original sequence {}
72-
Compare to other {3,2,1} is lexicographically largest.
73-
74-
Things to Note for the Candidate
75-
76-
You can use your own IDE like Visual Studio Code, Eclipse, or any other IDE that you are comfortable with to build your solution code.
77-
The IDE provided on the platform is purely for submission. Avoid using the IDE for coding out the solution.
78-
Test against any custom input in your own IDE. In the IDE provided on the platform, you cannot pass custom test cases and see the output.
79-
Use standard input and standard output in your program for the IDE to run the test cases smoothly against your code. We are giving a sample problem statement along with a solution that will pass the test cases in the IDE. - Sample Problem Statement (Right Click and Open in New Tab to view.)
80-
81-
82-
83-
*/
84-
85-
86-
/* package whatever; // don't place package name! */
87-
88-
import java.util.*;
89-
import java.lang.*;
90-
import java.io.*;
91-
92-
/* Name of the class has to be "Main" only if the class is public. */
93-
class Relevel_Test
94-
{
95-
96-
public static void main (String[] args) throws java.lang.Exception
97-
{
98-
// your code goes here
99-
Scanner sc = new Scanner(System.in);
100-
int m = sc.nextInt();
101-
int n = sc.nextInt();
102-
103-
int[] x = new int[m];
104-
int[] y = new int[n];
105-
106-
for (int a : x) {
107-
x[a] = sc.nextInt();
108-
}
109-
110-
for (int b : y) {
111-
y[b] = sc.nextInt();
112-
}
113-
}
114-
115-
public static int solve() {
116-
117-
}
118-
}
1+
//
2+
///*
3+
//Problem -> Solve History Ranking
4+
//
5+
//DUMB JERRY
6+
//DUMB JERRY
7+
//
8+
//Problem Statement
9+
//
10+
//As usual, Jerry and Tom are fighting. Tom wants to prove that Jerry is Dumb, So he made a problem and asked jerry.
11+
//
12+
//Given a sequence A of size N, and an operation.
13+
//
14+
//In one operation you can pick an element either from the front or back of the Sequence and write it down and delete it from the array.
15+
//Jerry has to perform the given operation until sequence A becomes empty.
16+
//
17+
//Tom wants the written sequence to be lexicographically maximum possible by performing the given operation on sequence A.
18+
//
19+
//Jerry can’t solve the problem on his own. So you have to help him.
20+
//
21+
//Note:-
22+
//
23+
//Sequence X of length N is lexicographically greater than Sequence Y of length N, if there exist such i (1<=i<=N), that Xi >Yi and for any j (1<=j<i) Xi=Yi.
24+
//
25+
//Constraint
26+
//
27+
//• 1 <= N <= 105
28+
//• 0 <= Ai <= 109
29+
//
30+
//• All input values are integer.
31+
//
32+
//Input Format
33+
//
34+
//• First-line contains N, length of the sequence A
35+
//
36+
//• Second line contains N space-separated integers denoting the sequence A.
37+
//
38+
//Output Format
39+
//
40+
//• In first print the lexicographically maximum sequence made by performing operations on sequence A
41+
//
42+
//Sample Input 1
43+
//
44+
//3
45+
//
46+
//3 1 2
47+
//
48+
//Sample Output 1
49+
//
50+
//3 2 1
51+
//
52+
//Explanation of Sample 1
53+
//
54+
//For test case1
55+
//
56+
//We get sequence {3,1,2} if we
57+
//Pick the element from the front of the sequence (3) and delete it from the original sequence {1,2}
58+
//Pick the element from the front of the sequence (3,1) and delete it from the original sequence {2}
59+
//Pick the element from the front of the sequence (3,1,2) and delete it from the original sequence {}
60+
//We get sequence {3,2,1} if we
61+
//Pick the element from the front of the sequence (3) and delete it from the original sequence {1,2}
62+
//Pick the element from the back of the sequence (3,2) and delete it from the original sequence {1}
63+
//Pick the element from the front of the sequence (3,2,1) and delete it from the original sequence {}
64+
//We get sequence {2,3,1} if we
65+
//Pick the element from the back of the sequence (2) and delete it from the original sequence {3,1}
66+
//Pick the element from the front of the sequence (2,3) and delete it from the original sequence {1}
67+
//Pick the element from the front of the sequence (2,3,1) and delete it from the original sequence {}
68+
//We get sequence {2,1,3} if we
69+
//Pick the element from the back of the sequence (2) and delete it from the original sequence {3,1}
70+
//Pick the element from the back of the sequence (2,1) and delete it from the original sequence {3}
71+
//Pick the element from the front of the sequence (2,1,3) and delete it from the original sequence {}
72+
//Compare to other {3,2,1} is lexicographically largest.
73+
//
74+
//Things to Note for the Candidate
75+
//
76+
//You can use your own IDE like Visual Studio Code, Eclipse, or any other IDE that you are comfortable with to build your solution code.
77+
//The IDE provided on the platform is purely for submission. Avoid using the IDE for coding out the solution.
78+
//Test against any custom input in your own IDE. In the IDE provided on the platform, you cannot pass custom test cases and see the output.
79+
//Use standard input and standard output in your program for the IDE to run the test cases smoothly against your code. We are giving a sample problem statement along with a solution that will pass the test cases in the IDE. - Sample Problem Statement (Right Click and Open in New Tab to view.)
80+
//
81+
//
82+
//
83+
// */
84+
//
85+
//
86+
///* package whatever; // don't place package name! */
87+
//
88+
//import java.util.*;
89+
//import java.lang.*;
90+
//import java.io.*;
91+
//
92+
///* Name of the class has to be "Main" only if the class is public. */
93+
//class Relevel_Test
94+
//{
95+
//
96+
// public static void main (String[] args) throws java.lang.Exception
97+
// {
98+
// // your code goes here
99+
// Scanner sc = new Scanner(System.in);
100+
// int m = sc.nextInt();
101+
// int n = sc.nextInt();
102+
//
103+
// int[] x = new int[m];
104+
// int[] y = new int[n];
105+
//
106+
// for (int a : x) {
107+
// x[a] = sc.nextInt();
108+
// }
109+
//
110+
// for (int b : y) {
111+
// y[b] = sc.nextInt();
112+
// }
113+
// }
114+
//
115+
// public static int solve() {
116+
//
117+
// }
118+
//}

arrays/2DArray.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
// 2d array 0 1 , sorted in asc order
2-
// min number of zeroes
3-
4-
/**
5-
* *
6-
* [0 0 0 0 0], -> 5
7-
* [0 0 0 0 0], -> 5
8-
* [0 1 1 1 1], -> 1
9-
* [1 1 1 1 1], -> 0
10-
*
11-
* [0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1]
12-
*
13-
* O(m.log n)
14-
*/
15-
16-
package arrays;
17-
18-
public class
19-
1+
//// 2d array 0 1 , sorted in asc order
2+
//// min number of zeroes
3+
//
4+
///**
5+
// * *
6+
// * [0 0 0 0 0], -> 5
7+
// * [0 0 0 0 0], -> 5
8+
// * [0 1 1 1 1], -> 1
9+
// * [1 1 1 1 1], -> 0
10+
// *
11+
// * [0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1]
12+
// *
13+
// * O(m.log n)
14+
// */
15+
//
16+
//package arrays;
17+
//
18+
//public class
19+
//
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
package arrays.interviewProblems;
3+
import java.util.*;
4+
// Website -> CodeStudio
5+
// Problem Name -> Aggressive Cows
6+
public class Aggressive_Cows
7+
{
8+
public static boolean isPossible(ArrayList<Integer> stalls, int k, int mid) {
9+
int cowCount = 1;
10+
int lastPos = stalls.get(0);
11+
12+
for(int i = 0; i < stalls.size(); i++) {
13+
if(stalls.get(i) - lastPos >= mid) {
14+
cowCount++;
15+
if(cowCount == k) {
16+
return true;
17+
}
18+
lastPos = stalls.get(i);
19+
}
20+
}
21+
return false;
22+
}
23+
24+
public static int aggressiveCows(ArrayList<Integer> stalls, int k)
25+
{
26+
// Write your code here.
27+
Collections.sort(stalls);
28+
int start = 0, max = -1;
29+
30+
for(int i = 0; i < stalls.size(); i++) {
31+
max = Math.max(max, stalls.get(i));
32+
}
33+
34+
int end = max;
35+
int ans = -1;
36+
37+
int mid = start + (end - start) / 2;
38+
while(start <= end) {
39+
if(isPossible(stalls, k, mid)) {
40+
ans = mid;
41+
start = mid + 1;
42+
}
43+
44+
else
45+
end = mid - 1;
46+
47+
mid = start + (end - start) / 2;
48+
}
49+
return ans;
50+
}
51+
52+
public static void main(String[] args) {
53+
54+
}
55+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package arrays;
2+
/* Problem Title :-> Minimum no. of operations required to make an arrays.array palindrome */
3+
public class Array_Problem_35 {
4+
5+
static int findMinOps(int[] a, int n) {
6+
7+
//Initialize result
8+
int ans = 0;
9+
10+
//Start from two corners
11+
for(int i=0,j=n-1;i<=j;) {
12+
13+
if(a[i] == a[j]) {
14+
i++;
15+
j--;
16+
}else if(a[i] > a[j]) {
17+
j--;
18+
a[j] += a[j+1];
19+
ans++;
20+
}else {
21+
i++;
22+
a[i] += a[i-1];
23+
ans++;
24+
}
25+
}
26+
return ans;
27+
}
28+
29+
public static void main(String[] args) {
30+
int[] a = new int[] {1,2,3,4,5,6,7,8,9,10};
31+
System.out.println("Count of minimum operations is " + findMinOps(a , a.length));
32+
}
33+
}

0 commit comments

Comments
 (0)