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
import java.util.*; | |
import java.util.stream.*; | |
class CountingConsecutiveElements { | |
public int countElements(int[] arr) { | |
Map<Integer, Integer> numberCounts = new HashMap<>(); | |
for(int num : arr) { | |
Integer wrappedNum = Integer.valueOf(num); |
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
import java.util.*; | |
import java.util.stream.*; | |
import static java.util.stream.Collectors.*; | |
class GroupAnagrams2 { | |
public List<List<String>> groupAnagrams(String[] wordsArray) { | |
Map<String,List<String>> anagramWords = new HashMap<>(); | |
for(String word : wordsArray) { | |
String key = calculateKey(word); |
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
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.stream.Collectors; | |
public class GroupAnagrams { | |
public static void main(String[] args) { | |
GroupAnagrams problem = new GroupAnagrams(); | |
List<List<String>> result1 = problem.groupAnagrams(new String[] { "eat", "tea", "tan", "ate", "nat", "bat" }); |
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
import java.util.Arrays; | |
import java.util.stream.Collectors; | |
public class MoveZeroesOptimal { | |
public static void main(String[] args) { | |
MoveZeroesOptimal problem = new MoveZeroesOptimal(); | |
int[] result1 = problem.calculate(new int[] { 0, 1, 0, 3, 12 }); | |
System.out.println( | |
"Expected: [1,3,12,0,0], " + "Result: " + Arrays.stream(result1).boxed().collect(Collectors.toList())); |
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
import java.util.Arrays; | |
import java.util.stream.Collectors; | |
public class MoveZeroes { | |
public static void main(String[] args) { | |
MoveZeroes problem = new MoveZeroes(); | |
int[] result1 = problem.calculate(new int[] { 0, 1, 0, 3, 12 }); | |
System.out.println( | |
"Expected: [1,3,12,0,0], " + "Result: " + Arrays.stream(result1).boxed().collect(Collectors.toList())); |
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 class MaxSubArray { | |
public static void main(String[] args) { | |
MaxSubArray problem = new MaxSubArray(); | |
int result1 = problem.calculate(new int[] { -2,1,-3,4,-1,2,1,-5,4 }); | |
System.out.println("Expected: 6, Result: " + result1); | |
} | |
public int calculate(int[] nums) { |
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
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
public class HappyNumber { | |
public static void main(String[] args) { | |
HappyNumber problem = new HappyNumber(); | |
boolean result1 = problem.isHappy(19); |
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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { val = x; } | |
* } | |
*/ | |
class LinkedListMiddleNodeFastPointer { | |
public ListNode middleNode(ListNode head) { |
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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { val = x; } | |
* } | |
*/ | |
class LinkedListMiddleNode { |
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
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ |
NewerOlder