Skip to content

Commit 37aecd3

Browse files
author
Dhananjay Nagargoje
committed
bunch of code
1 parent 5392a3a commit 37aecd3

File tree

29 files changed

+1120
-686
lines changed

29 files changed

+1120
-686
lines changed

Diff for: .idea/workspace.xml

+570-635
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: out/production/main/input.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6 6 4

Diff for: out/production/main/output.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4
65 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-1.05 KB
Binary file not shown.
671 Bytes
Binary file not shown.

Diff for: out/production/main/problems/test/One.class

118 Bytes
Binary file not shown.

Diff for: out/production/main/testingsystem/misccode/input.txt

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
1
2-
7
3-
1 2
4-
1 3
5-
2 4
6-
2 5
7-
4 6
8-
4 7
9-
1+
6 6 4
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
4

Diff for: src/main/java/Solution.java

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution implements Runnable {
5+
6+
BufferedReader in;
7+
PrintWriter out;
8+
StringTokenizer tok = new StringTokenizer("");
9+
10+
public static void main(String[] args) {
11+
new Thread(null, new Solution(), "", 256 * (1L << 20)).start();
12+
}
13+
14+
public void run() {
15+
try {
16+
long t1 = System.currentTimeMillis();
17+
if (System.getProperty("ONLINE_JUDGE") != null) {
18+
in = new BufferedReader(new InputStreamReader(System.in));
19+
out = new PrintWriter(System.out);
20+
} else {
21+
in = new BufferedReader(new FileReader("src\\main\\java\\testingsystem\\misccode\\input.txt"));
22+
out = new PrintWriter("src\\main\\java\\testingsystem\\misccode\\output.txt");
23+
}
24+
Locale.setDefault(Locale.US);
25+
solve();
26+
in.close();
27+
out.close();
28+
long t2 = System.currentTimeMillis();
29+
System.err.println("Time = " + (t2 - t1));
30+
} catch (Throwable t) {
31+
t.printStackTrace(System.err);
32+
System.exit(-1);
33+
}
34+
}
35+
36+
String readString() throws IOException {
37+
while (!tok.hasMoreTokens()) {
38+
tok = new StringTokenizer(in.readLine());
39+
}
40+
return tok.nextToken();
41+
}
42+
43+
int readInt() throws IOException {
44+
return Integer.parseInt(readString());
45+
}
46+
47+
long readLong() throws IOException {
48+
return Long.parseLong(readString());
49+
}
50+
51+
double readDouble() throws IOException {
52+
return Double.parseDouble(readString());
53+
}
54+
55+
// solution
56+
57+
void solve() throws IOException {
58+
long n = readInt();
59+
long m = readInt();
60+
long a = readInt();
61+
long xn = n/a;
62+
long xm = m/a;
63+
if(n % a != 0) xn++;
64+
if(m % a != 0) xm++;
65+
out.print((xn*xm));
66+
67+
}
68+
69+
}

Diff for: src/main/java/input.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6 6 4

Diff for: src/main/java/oopadesign/moviebookingticket.md

+1-26
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Admin extends Person {
5353
public boolean addMovie(Movie movie);
5454
public boolean addShow(Show show);
5555
public boolean blockUser(Customer customer);
56-
}
56+
}
5757

5858
public class FrontDeskOfficer extends Person {
5959
public boolean createBooking(Booking booking);
@@ -119,31 +119,6 @@ public class Payment {
119119

120120

121121

122-
public class City {
123-
private String name;
124-
private String state;
125-
private String zipCode;
126-
}
127-
128-
public class Cinema {
129-
private String name;
130-
private int totalCinemaHalls;
131-
private Address location;
132-
133-
private List<CinemaHall> halls;
134-
}
135-
136-
public class CinemaHall {
137-
private String name;
138-
private int totalSeats;
139-
140-
private List<CinemaHallSeat> seats;
141-
private List<Show> shows;
142-
}
143-
144-
145-
146-
147122
public class City {
148123
private String name;
149124
private String state;

Diff for: src/main/java/output.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package problems.onRecursionAndDp.backtracking;
2+
3+
import java.util.ArrayList;
4+
5+
public class PalindriomSequcne {
6+
public static class Solution {
7+
ArrayList<ArrayList<String>> res ;
8+
public ArrayList<ArrayList<String>> partition(String a) {
9+
res = new ArrayList<>();
10+
func(a, 0, 0, new ArrayList<>());
11+
return res;
12+
}
13+
14+
public void func(String a, int parst, int curi, ArrayList<String> step) {
15+
if(curi == a.length()-1){
16+
if(ispalindrom(a, parst, curi)) {
17+
step.add(a.substring(parst, curi+1));
18+
res.add(new ArrayList<>(step));
19+
step.remove(step.size()-1);
20+
}
21+
return;
22+
}
23+
if(ispalindrom(a, parst, curi)) {
24+
step.add(a.substring(parst, curi+1));
25+
func(a, curi+1, curi+1, step);
26+
step.remove(step.size()-1);
27+
}
28+
func(a, parst, curi+1, step);
29+
}
30+
private boolean ispalindrom(String str, int st, int en) {
31+
while(st<=en){
32+
if(str.charAt(st)!=str.charAt(en)) return false;
33+
st++;
34+
en--;
35+
}
36+
return true;
37+
}
38+
}
39+
40+
public static void main(String[] args) {
41+
Solution solution
42+
= new Solution();
43+
// solution.partition("cccaacbcaabb");
44+
solution.partition("aabac").stream().forEach(strings -> System.out.println(strings));
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package problems.onRecursionAndDp.backtracking;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.HashSet;
6+
7+
public class RemoveInvalidParenthesis {
8+
public static class Solution {
9+
ArrayList<String> res;
10+
HashSet<String> seen;
11+
12+
public ArrayList<String> solve(String A) {
13+
res = new ArrayList<>();
14+
seen = new HashSet<>();
15+
func(A, 0, invalidParen(A));
16+
return res;
17+
}
18+
19+
public void func(String str, int i, int k) {
20+
if (k == 0 || i == str.length()) {
21+
if (k == 0 && invalidParen(str) == 0) {
22+
if (!seen.contains(str))
23+
res.add(str);
24+
seen.add(str);
25+
}
26+
return;
27+
}
28+
if (str.charAt(i) == '(' || str.charAt(i) == ')') {
29+
String left = (i > 0) ? str.substring(0, Math.min(i, str.length())) : "";
30+
String right = (i < str.length() - 1) ? str.substring(i + 1, str.length()) : "";
31+
func(left + right, i, k - 1);
32+
}
33+
func(str, i + 1, k);
34+
}
35+
36+
public int invalidParen(String A) {
37+
int left = 0;
38+
int right = 0;
39+
int count = 0;
40+
for (int i = 0; i < A.length(); i++) {
41+
if (A.charAt(i) == '(') left++;
42+
if (A.charAt(i) == ')') {
43+
right++;
44+
if (right > left) {
45+
count++;
46+
left = 0;
47+
right = 0;
48+
} else {
49+
left-=right;
50+
right--;
51+
}
52+
}
53+
}
54+
count += left;
55+
return count;
56+
}
57+
}
58+
59+
public static void main(String[] args) {
60+
Solution solution = new Solution();
61+
System.out.println(solution.solve(")(()((((()((").toString());
62+
}
63+
64+
}

Diff for: src/main/java/problems/onbinarytree/PostOrder.java

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package problems.onbinarytree;
2+
3+
import java.util.ArrayList;
4+
import java.util.Deque;
5+
import java.util.HashSet;
6+
import java.util.LinkedList;
7+
8+
public class PostOrder {
9+
10+
public static ArrayList<Integer> postorderTraversal(TreeNode A) {
11+
ArrayList<Integer> res = new ArrayList<>();
12+
if(A == null) return res;
13+
TreeNode prevLeft = null;
14+
TreeNode prevRight = null;
15+
16+
Deque<TreeNode> deq = new LinkedList<>();
17+
deq.addLast(A);
18+
HashSet<TreeNode> seen = new HashSet<>();
19+
while(!deq.isEmpty()) {
20+
while(deq.peekLast().left != null && !seen.contains(deq.peekLast().left)) {
21+
deq.addLast(deq.peekLast().left);
22+
}
23+
24+
if(deq.peekLast().right != null) {
25+
if(seen.contains(deq.peekLast().right)){
26+
TreeNode child = deq.removeLast();
27+
res.add(child.val);
28+
seen.add(child);
29+
} else {
30+
deq.addLast(deq.peekLast().right);
31+
}
32+
} else {
33+
TreeNode child = deq.removeLast();
34+
res.add(child.val);
35+
seen.add(child);
36+
}
37+
38+
}
39+
//helper(A, res);
40+
return res;
41+
}
42+
43+
public static void main(String[] args) {
44+
TreeNode root = new TreeNode();
45+
46+
//level 0
47+
root.val = 1;
48+
49+
//level 1
50+
root.left = new TreeNode(2);
51+
root.right = new TreeNode(3);
52+
53+
//level 2
54+
root.left.left = new TreeNode(4);
55+
root.left.right = new TreeNode(5);
56+
root.right.left = new TreeNode(6);
57+
root.right.right = new TreeNode(7);
58+
59+
postorderTraversal(root).forEach(System.out::println);
60+
}
61+
}

Diff for: src/main/java/problems/onbinarytree/TreeNode.java

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public class TreeNode {
55
public TreeNode left;
66
public TreeNode right;
77

8+
public TreeNode() {
9+
}
810
public TreeNode(int x) {
911
val = x;
1012
}

Diff for: src/main/java/problems/onbinarytree/TreeTraversal.java

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static void levelOrder(BinaryTreeNode<Integer> root) {
120120
}
121121
}
122122

123+
123124
public static void main(String[] args) {
124125
System.out.print("pre -> ");preOrder(BinaryTreeUtils.getSampleTree(2));
125126
System.out.print("\npre -> ");nonRecursivePreOrder(BinaryTreeUtils.getSampleTree(4));

Diff for: src/main/java/problems/onheaps/KLargestInHeap.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ public HeapEntry(int val, int index) {
2828

2929
public static List<Integer> kLargestInBinaryHeap(List<Integer> A, int k) {
3030
List<Integer> res = new ArrayList<>();
31-
PriorityQueue<HeapEntry> levelPq = new PriorityQueue<>(new Comparator<HeapEntry>() {
32-
@Override
33-
public int compare(HeapEntry o1, HeapEntry o2) {
34-
return o2.val - o1.val; //reverse comparater
35-
}
31+
PriorityQueue<HeapEntry> levelPq = new PriorityQueue<>((o1, o2) -> {
32+
return o2.val - o1.val; //reverse comparater
3633
});
3734
if (A.size() == 0) return res;
3835
levelPq.add(new HeapEntry(A.get(0), 0));

0 commit comments

Comments
 (0)