Skip to content

Commit f48df0d

Browse files
committed
problem solving start
0 parents  commit f48df0d

File tree

7 files changed

+546
-0
lines changed

7 files changed

+546
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
3+
*/
4+
class KadaneAlgorithmMaxSubarray {
5+
public static void main(String args[]){
6+
7+
System.out.println(maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
8+
}
9+
public static int maxSubArray(int[] nums) {
10+
int prev_sum = nums[0], max_global = nums[0];
11+
for (int i = 1; i < nums.length; i++ ){
12+
prev_sum = (nums[i] > (prev_sum + nums[i]))?nums[i]:(prev_sum + nums[i]);
13+
14+
if(prev_sum > max_global)
15+
max_global = prev_sum;
16+
}
17+
18+
return max_global;
19+
}
20+
}
+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import java.util.*;
2+
3+
class Node{
4+
int value;
5+
Node left;
6+
Node right;
7+
8+
Node(int value){
9+
this.value = value;
10+
this.left=null;
11+
this.right=null;
12+
}
13+
14+
}
15+
16+
class MinStack {
17+
18+
List<Integer> list;
19+
int item = 0;
20+
/** initialize your data structure here. */
21+
public MinStack() {
22+
list = new ArrayList<Integer>();
23+
}
24+
25+
public void push(int x) {
26+
list.add(x);
27+
item++;
28+
}
29+
30+
public void pop() {
31+
list.remove(item);
32+
item--;
33+
}
34+
35+
public int top() {
36+
return list.get(item);
37+
}
38+
39+
public int getMin() {
40+
int min = list.get(0);
41+
for(int i =0;i<list.size();i++){
42+
if(min>list.get(i))
43+
min=list.get(i);
44+
}
45+
return min;
46+
}
47+
}
48+
49+
class BinaryTree{
50+
51+
Node root;
52+
53+
private Node addrecursively(Node current, int value){
54+
if(current == null)
55+
return new Node(value);
56+
57+
else if(value < current.value)
58+
current.left = addrecursively(current.left, value);
59+
else if(value > current.value)
60+
current.right = addrecursively(current.right, value);
61+
else
62+
return current;
63+
return current;
64+
65+
}
66+
67+
public void add(int value){
68+
root = addrecursively(root, value);
69+
}
70+
71+
public void traverseDfsInorder(Node node){
72+
73+
if(node!=null){
74+
traverseDfsInorder(node.left);
75+
System.out.print(" "+node.value);
76+
traverseDfsInorder(node.right);
77+
}
78+
79+
}
80+
81+
public void traverseDfsPreorder(Node node){
82+
83+
if(node!=null){
84+
System.out.print(" "+node.value);
85+
traverseDfsInorder(node.left);
86+
traverseDfsInorder(node.right);
87+
}
88+
89+
}
90+
91+
public void traverseDfsPostorder(Node node){
92+
93+
if(node!=null){
94+
traverseDfsInorder(node.left);
95+
traverseDfsInorder(node.right);
96+
System.out.print(" "+node.value);
97+
}
98+
99+
}
100+
101+
public void printTree(){
102+
System.out.println("Inorder: ");
103+
traverseDfsInorder(root);
104+
105+
System.out.println("\nPreorder: ");
106+
traverseDfsPreorder(root);
107+
108+
System.out.println("\nPostorder: ");
109+
traverseDfsPostorder(root);
110+
}
111+
112+
}
113+
114+
115+
116+
public class BinaryTreeCreator {
117+
118+
public static void main(String args[]){
119+
BinaryTree tree = new BinaryTree();
120+
tree.add(11);
121+
tree.add(15);
122+
tree.add(41);
123+
tree.add(8);
124+
tree.add(6);
125+
tree.add(45);
126+
tree.add(75);
127+
tree.add(23);
128+
tree.add(3);
129+
tree.add(9);
130+
131+
System.out.println("-----Traversing order----");
132+
tree.printTree();
133+
134+
MinStack min = new MinStack();
135+
min.push(-1);
136+
// min.pop();
137+
min.push(2);
138+
min.push(6);
139+
System.out.println(min.getMin());
140+
}
141+
142+
}

data-structures/JavaLearningLinks.txt

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
Data Structures and Algorithms Topics:
2+
https://www.codechef.com/certification/prepare#foundation
3+
https://medium.com/basecs
4+
(I read from the second link)
5+
6+
7+
Java Topics : http://javahungry.blogspot.com/2013/08/hashing-how-hash-map-works-in-java-or.html
8+
9+
http://javahungry.blogspot.com/2014/06/how-treemap-works-ten-treemap-java-interview-questions.html
10+
11+
http://javahungry.blogspot.com/2015/02/how-concurrenthashmap-works-in-java-internal-implementation.html
12+
13+
http://javahungry.blogspot.com/2015/10/how-treeset-works-internally-in-java-interview-questions.html
14+
15+
http://javahungry.blogspot.com/p/threads.html
16+
17+
18+
http://javarevisited.blogspot.in/2011/04/synchronization-in-java-synchronized.html
19+
20+
http://javarevisited.blogspot.in/2011/06/volatile-keyword-java-example-tutorial.html
21+
22+
http://mrbool.com/working-with-java-executor-framework-in-multithreaded-application/27560
23+
24+
http://stackoverflow.com/questions/10828863/what-the-use-of-custom-class-loader
25+
26+
http://stackoverflow.com/questions/10901752/what-is-the-significance-of-load-factor-in-hashmap
27+
28+
http://stackoverflow.com/questions/11011291/treeset-internally-uses-treemap-so-is-it-required-to-implement-hashcode-method
29+
30+
http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons
31+
32+
http://stackoverflow.com/questions/13855013/understanding-java-memory-management
33+
34+
http://stackoverflow.com/questions/2087469/sort-a-file-with-huge-volume-of-data-given-memory-constraint
35+
36+
http://stackoverflow.com/questions/27325997/how-does-countdownlatch-works-in-java
37+
38+
http://stackoverflow.com/questions/56860/what-is-the-liskov-substitution-principle
39+
40+
http://stackoverflow.com/questions/8161896/example-code-to-show-how-java-synchronized-block-works
41+
42+
http://tutorials.jenkov.com/java-concurrency/synchronized.html
43+
44+
http://tutorials.jenkov.com/java-util-concurrent/cyclicbarrier.html
45+
46+
http://www.dynatrace.com/en/javabook/how-garbage-collection-works.html
47+
48+
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html
49+
50+
http://www.programcreek.com/2013/03/hashmap-vs-treemap-vs-hashtable-vs-linkedhashmap/
51+
52+
https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/garbage_collect.html
53+
54+
https://en.m.wikipedia.org/wiki/Creational_pattern
55+
56+
https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
57+
58+
https://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/
59+
60+
https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
61+
62+
https://www.pluralsight.com/courses/introduction-to-sql
63+
64+
http://www.programmerinterview.com/index.php/database-sql/sql-having-vs-group-by/
65+
66+
http://www.programmerinterview.com/index.php/database-sql/inner-vs-outer-joins/
67+
68+
https://www.essentialsql.com/what-is-a-query-plan/
69+
70+
http://www.dotnettricks.com/learn/sqlserver/understanding-case-expression-in-sql-server-with-example
71+
72+
73+
74+
---------------------------------------------------------------------------------------------
75+
76+
77+
Self Added Topics:
78+
79+
Garbage Collection :
80+
https://betsol.com/tag/garbage-collection/
81+
82+
Executor Services :
83+
http://www.baeldung.com/java-executor-service-tutorial
84+
85+
Atomic Variables:
86+
http://www.baeldung.com/java-atomic-variables
87+
88+
Thread Pools:
89+
http://www.baeldung.com/thread-pool-java-and-guava
90+
91+
Fork Join:
92+
http://www.baeldung.com/java-fork-join
93+
94+
Complete Thread Articles:
95+
http://tutorials.jenkov.com/java-util-concurrent/index.html
96+
(Refer codes)
97+
98+
Fair knowledge of Thread and Heap Dump.
99+
Knowledge of various garbage collection algorithms
100+
101+
102+
103+
singleton
104+
https://javarevisited.blogspot.com/2011/03/10-interview-questions-on-singleton.html
105+
106+
Reflection: How to Call private method
107+
https://javarevisited.blogspot.com/2012/05/how-to-access-private-field-and-method.html

0 commit comments

Comments
 (0)