diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 000000000..26d33521a
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 000000000..919ce1f1f
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 000000000..a55e7a179
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 000000000..b589d56e9
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 000000000..ba1ec5c7e
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 000000000..d20b5975a
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..668048d36
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb
new file mode 100644
index 000000000..e69de29bb
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 000000000..e96534fb2
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..35eb1ddfb
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/ByteByByte/src/CodingInterviewQuestions/Array/P1_MedianOfArrays/Java/Solution.java b/src/ByteByByte/src/CodingInterviewQuestions/Array/P1_MedianOfArrays/Java/Solution.java
index 83c52ae64..32e5a55eb 100644
--- a/src/ByteByByte/src/CodingInterviewQuestions/Array/P1_MedianOfArrays/Java/Solution.java
+++ b/src/ByteByByte/src/CodingInterviewQuestions/Array/P1_MedianOfArrays/Java/Solution.java
@@ -16,21 +16,21 @@ public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
int r = len1;
//find the m1 so that nums1[m1] >= nums2[m2 - 1]
while(l < r){
- int m1 = l + (r - l) / 2;
- int m2 = k - m1;
- if (nums1[m1] < nums2[m2 - 1]) {
- l = m1 + 1;
+ int nums1ArrayIndex = l + (r - l) / 2;
+ int nums2ArrayIndex = k - nums1ArrayIndex;
+ if (nums1[nums1ArrayIndex] < nums2[nums2ArrayIndex - 1]) {
+ l = nums1ArrayIndex + 1;
} else {
- r = m1;
+ r = nums1ArrayIndex;
}
}
- int m1 = l;
- int m2 = k - l;
- int c1 = Math.max(m1 <= 0 ? Integer.MIN_VALUE : nums1[m1 - 1],
- m2 <= 0? Integer.MIN_VALUE: nums2[m2 - 1]);
+ int nums1ArrayIndex = l;
+ int nums2ArrayIndex = k - l;
+ int c1 = Math.max(nums1ArrayIndex <= 0 ? Integer.MIN_VALUE : nums1[nums1ArrayIndex - 1],
+ nums2ArrayIndex <= 0? Integer.MIN_VALUE: nums2[nums2ArrayIndex - 1]);
if ((len1 + len2) % 2 ==1) return c1;
- int c2 = Math.min(m1 >= len1 ? Integer.MAX_VALUE : nums1[m1],
- m2 >= len2 ? Integer.MAX_VALUE: nums2[m2]);
+ int c2 = Math.min(nums1ArrayIndex >= len1 ? Integer.MAX_VALUE : nums1[nums1ArrayIndex],
+ nums2ArrayIndex >= len2 ? Integer.MAX_VALUE: nums2[nums2ArrayIndex]);
return (c1 + c2) / 2.0;
}
}
\ No newline at end of file
diff --git a/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D18_QueuesAndStacks/Java/Solution.java b/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D18_QueuesAndStacks/Java/Solution.java
index 8dc41400a..9157e5d54 100644
--- a/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D18_QueuesAndStacks/Java/Solution.java
+++ b/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D18_QueuesAndStacks/Java/Solution.java
@@ -23,6 +23,14 @@ public static void main(String[] args) {
}
// Pop/Dequeue the chars at the head of both data structures and compare them:
+ boolean isPalindrome = isPalindrome(s, p);
+
+ //Finally, print whether string s is palindrome or not.
+ System.out.println( "The word, " + input + ", is "
+ + ( (!isPalindrome) ? "not a palindrome." : "a palindrome." ) );
+ }
+
+ private static boolean isPalindrome(char[] s, Solution p) {
boolean isPalindrome = true;
for (int i = 0; i < s.length/2; i++) {
if (p.popCharacter() != p.dequeueCharacter()) {
@@ -30,10 +38,7 @@ public static void main(String[] args) {
break;
}
}
-
- //Finally, print whether string s is palindrome or not.
- System.out.println( "The word, " + input + ", is "
- + ( (!isPalindrome) ? "not a palindrome." : "a palindrome." ) );
+ return isPalindrome;
}
}
diff --git a/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Node.java b/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Node.java
new file mode 100644
index 000000000..d84575bea
--- /dev/null
+++ b/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Node.java
@@ -0,0 +1,42 @@
+package HackerRank.src.Tracks.Tutorials.ThirtyDaysOfCode.D22_BinarySearchTrees.Java;
+
+public class Node{
+ Node left,right;
+ int data;
+ Node(){
+ }
+
+ Node(int data){
+ this.data=data;
+ left=right=null;
+ }
+
+
+ public static Node insert(Node root,int data){
+ if(root==null){
+ return new Node(data);
+ }
+ else{
+ Node cur;
+ if(data<=root.data){
+ cur=insert(root.left,data);
+ root.left=cur;
+ }
+ else{
+ cur=insert(root.right,data);
+ root.right=cur;
+ }
+ return root;
+ }
+ }
+
+ public static int getHeight(Node root){
+ if (root == null){
+ return -1;
+ }
+ else {
+ return 1+ Math.max(getHeight(root.left), getHeight(root.right));
+ }
+ }
+}
+
diff --git a/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Solution.java b/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Solution.java
index 2bd47ac6b..0b701b136 100644
--- a/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Solution.java
+++ b/src/HackerRank/src/Tracks/Tutorials/ThirtyDaysOfCode/D22_BinarySearchTrees/Java/Solution.java
@@ -5,51 +5,17 @@
public class Solution {
public static void main(String[] args) {
+ Node node = new Node();
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
Node root=null;
while(T-->0){
int data=sc.nextInt();
- root=insert(root,data);
+ root=node.insert(root,data);
}
- int height=getHeight(root);
+ int height=node.getHeight(root);
System.out.println(height);
sc.close();
}
-
- public static Node insert(Node root,int data){
- if(root==null){
- return new Node(data);
- }
- else{
- Node cur;
- if(data<=root.data){
- cur=insert(root.left,data);
- root.left=cur;
- }
- else{
- cur=insert(root.right,data);
- root.right=cur;
- }
- return root;
- }
- }
-
- public static int getHeight(Node root){
- if (root == null){
- return -1;
- }
- else {
- return 1+ Math.max(getHeight(root.left), getHeight(root.right));
- }
- }
}
-class Node{
- Node left,right;
- int data;
- Node(int data){
- this.data=data;
- left=right=null;
- }
-}
\ No newline at end of file
diff --git a/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/FirstMissingPositive/Java/Solution.java b/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/FirstMissingPositive/Java/Solution.java
index 85984e1f3..6e2ff3099 100644
--- a/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/FirstMissingPositive/Java/Solution.java
+++ b/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/FirstMissingPositive/Java/Solution.java
@@ -1,6 +1,7 @@
package LeetCode.src.Explore.Interview.GoogleInterview.ArraysAndStrings.FirstMissingPositive.Java;
+import LeetCode.src.SwapNumbersInArray;
-public class Solution {
+public class Solution extends SwapNumbersInArray {
public static void main(String[] args) {
int[] input = {3, 4, -1, 1};
int result = findMissingPositive(input);
@@ -37,9 +38,4 @@ public static int findMissingPositive(int[] nums) {
}
- private static void swap(int[] nums, int i, int j) {
- int temp = nums[i];
- nums[i] = nums[j];
- nums[j] = temp;
- }
}
\ No newline at end of file
diff --git a/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/ReadNCharactersGivenRead4/Java/Reader4.java b/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/ReadNCharactersGivenRead4/Java/Reader4.java
index 648d45709..21545ad67 100644
--- a/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/ReadNCharactersGivenRead4/Java/Reader4.java
+++ b/src/LeetCode/src/Explore/Interview/GoogleInterview/ArraysAndStrings/ReadNCharactersGivenRead4/Java/Reader4.java
@@ -4,4 +4,29 @@ public class Reader4 {
int read4(char[] buf) {
return 4;
}
+
+
+ /**
+ * @param buf Destination buffer
+ * @param n Maximum number of characters to read
+ * @return The number of characters read
+ */
+ public int read(char[] buf, int n) {
+ char[] buffer = new char[4];
+ boolean endOfFile = false;
+ int readBytes = 0; // bytes read so far
+
+ while (readBytes < n && !endOfFile) {
+ int currentReadBytes = read4(buffer);
+ if (currentReadBytes != 4) {
+ endOfFile = true;
+ }
+ int length = Math.min(n - readBytes, currentReadBytes);
+ for (int i=0; i