Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/Hashing-2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions ContiguousArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.HashMap;

public class ContiguousArray {
public int findMaxLength(int[] nums) {
if(nums == null || nums.length == 0) return 0;
//Create HashMap to store running sum & corresponding index
HashMap<Integer, Integer> map = new HashMap<>();
int rSum = 0;
int max = 0;
map.put(0,-1); //create dummy entry in map to catch initial ssubarray
for(int i = 0; i < nums.length; i++){
if(nums[i] == 0){
rSum = rSum - 1;
} else {
rSum = rSum + 1;
}
if(map.containsKey(rSum)){
int curr = i - map.get(rSum);
max = Math.max(max, curr);
} else {
map.put(rSum, i);
}
}
return max;
}
}
28 changes: 28 additions & 0 deletions LongestPalindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.HashSet;

public class LongestPalindrome {
public static int longestPalindrome(String s) {
HashSet<Character> set = new HashSet<>();
int count = 0;
for(int i = 0; i < s.length(); i++){
char ch = s.charAt(i);
//Check in hashset if elements exists, if pair matches then remove from set else add it
if(set.contains(ch)){
set.remove(ch);
count +=2;
}else{
set.add(ch);
}
}
//If hashset is not empty then add 1 of the element from set
if(!set.isEmpty()){
count++;
}
return count;
}
public static void main(String[] args){
String s = "abccccdd";
System.out.println(longestPalindrome(s));
}

}
26 changes: 26 additions & 0 deletions SubarraySum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.HashMap;

public class SubarraySum {
public int subarraySum(int[] nums, int k) {
//create a variable for running sum
int rSum = 0;
HashMap<Integer, Integer> map = new HashMap<>();
map.put(0,1);
int count = 0;
for(int i = 0; i < nums.length; i ++){
rSum = rSum + nums[i];
if(map.containsKey(rSum - k)){
count = count + map.get(rSum - k);
}
if(!map.containsKey(rSum)){
map.put(rSum,1);
}else {
map.put(rSum, map.get(rSum)+1);
}
}
return count;
}
}

//Time complexity : O(n)
//Space complexity : O(n)
3 changes: 3 additions & 0 deletions out/production/Hashing-2/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions out/production/Hashing-2/.idea/Hashing-2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions out/production/Hashing-2/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions out/production/Hashing-2/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/Hashing-2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions out/production/Hashing-2/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/Hashing-2/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added out/production/Hashing-2/LongestPalindrome.class
Binary file not shown.
12 changes: 12 additions & 0 deletions out/production/Hashing-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Hashing-2

Explain your approach in **three sentences only** at top of your code


## Problem1 (https://leetcode.com/problems/subarray-sum-equals-k/)


## Problem2 (https://leetcode.com/problems/contiguous-array/)


## Problem3 (https://leetcode.com/problems/longest-palindrome)