This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public String longestPalindrome(String str) { | |
int index1=0; | |
int index2=0; | |
boolean isPalin = true; | |
if(str.length()==0) { | |
return str; | |
} | |
if(str.length()==1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// java.util.* and java.util.streams.* have been imported for this problem. | |
// You don't need any other imports. | |
public static ArrayList<Interval> insertRange(ArrayList<Interval> intervalsList, Interval insert) { | |
ArrayList<Interval> merged = new ArrayList<Interval>(); | |
if(intervalsList.size() == 0) { | |
merged.add(insert); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int makeChange(int[] coins, int amount) { | |
if (coins != null && coins.length > 0 && amount >= 0) | |
return makeChange(coins,amount,0); | |
return 0; | |
} | |
public static int makeChange(int[] coins, int amount, int current_coin_index) { | |
int next_coin_index; | |
if (current_coin_index < coins.length - 1){ | |
//If the coin index is less than the last index, increment the index. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// java.util.* and java.util.streams.* have been imported for this problem. | |
// You don't need any other imports. | |
public static int makeChange(int[] coins, int amount) { | |
int counter = 0; | |
int currentCoinIndex = 0; | |
Integer[] answer = new Integer[1]; | |
answer[0] = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// java.util.* and java.util.streams.* have been imported for this problem. | |
// You don't need any other imports. | |
public static ArrayList<String> generateIPAddrs(String s) { | |
Stack<IpLevelNode> st = new Stack<>(); | |
ArrayList<String> answer = new ArrayList<>(); | |
Character c = s.charAt(0); | |
Integer numValue = Character.getNumericValue(c); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ArrayList<Interval> insertRange(ArrayList<Interval> intervalsList, Interval insert) { | |
ArrayList<Interval> out = new ArrayList<>(); | |
for(Interval i: intervalsList){ | |
if(i.end < insert.start) { | |
out.add(i); | |
} | |
else if(i.start > insert.end) { | |
out.add(insert); | |
insert = i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// java.util.* and java.util.streams.* have been imported for this problem. | |
// You don't need any other imports. | |
public static int matrixMaxSumDfs(int[][] grid) { | |
int[] sum = new int[1]; | |
int answer = helper(grid, 0, 0, sum); | |
return answer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public TreeNode delete(TreeNode root, int data) { | |
if(root == null) { | |
return null; | |
} else if(data < root.data) { | |
root.left = delete(root.left, data); | |
} else if(data > root.data) { | |
root.right = delete(root.right, data); | |
} else { //element found | |
if(root.left != null && root.right != null) { //full node case | |
root.data = findMin(root.right).data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int longestNRSubstringLen(String input) { | |
if(input==null) | |
return 0; | |
char[] array = input.toCharArray(); | |
int prev = 0; | |
HashMap<Character, Integer> characterMap = new HashMap<Character, Integer>(); | |
for (int i = 0; i < array.length; i++) { | |
if (!characterMap.containsKey(array[i])) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ListNode sumTwoLinkedLists(ListNode input1, ListNode input2) { | |
int carryComponent =0; | |
ListNode returnHead = new ListNode(0); | |
ListNode n1 = input1, n2 = input2, n3=returnHead; | |
while(n1 != null || n2 != null){ | |
if(n1 != null){ | |
carryComponent += n1.data; | |
n1 = n1.next; |