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 UnmixStrings { | |
public static void main(String[] args) { | |
System.out.println(String.format("Input: hTsii s aimex dpus rtni.g, Output: %s",unmix("hTsii s aimex dpus rtni.g"))); | |
System.out.println(String.format("Input: 214365, Output: %s",unmix("214365"))); | |
System.out.println(String.format("Input: badce, Output: %s",unmix("badce"))); | |
} | |
public static String unmix(String str) { | |
StringBuilder sb = new StringBuilder(); | |
int length = str.length(); | |
boolean oddLength = !(length%2==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
import java.util.Arrays; | |
public class LargestGap { | |
public static void main(String[] args) { | |
System.out.println(largestGap(new int[]{9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5})); | |
} | |
public static int largestGap(int[] numbers) { | |
int result = 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
/** | |
* Deepak Singhvi | |
*/ | |
public class MaxLoot { | |
public static int maxLoot(int input[], int inputSize) | |
{ | |
if (inputSize == 0) | |
return 0; | |
if (inputSize == 1) | |
return input[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
public class MaximumSumOfHourGlassInMatrix { | |
private static int[][] input1 = { | |
{1, 2, 3, 4, 5}, | |
{0, 5, 1, 5, 2}, | |
{0, 0, 0, 1, 3}, | |
{4, 1, 1, 0, 1}, | |
{0, 0, 0, 0, 3}, | |
}; |
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
/** | |
* Author: Deepak Singhvi | |
*/ | |
public class StackDeque extends DequeueImpl { | |
public static void main(String args[]) { | |
StackDeque stack = new StackDeque(); | |
stack.push(1); | |
stack.push(2); | |
stack.push(3); |
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
/** | |
* Author: Deepak Singhvi | |
*/ | |
public class QueueDeque extends DequeueImpl { | |
public static void main(String args[]) { | |
QueueDeque queue = new QueueDeque(); | |
queue.enqueue(1); | |
queue.enqueue(2); | |
queue.enqueue(3); |
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
/** | |
* Author: Deepak Singhvi | |
*/ | |
class DequeueImpl { | |
private Deque head; | |
private Deque tail; | |
public DequeueImpl() { | |
} |
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
/** | |
* Author: Deepak Singhvi | |
*/ | |
class Deque { | |
private Integer data; | |
Deque next; | |
Deque prev; | |
public Integer getData() { |
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.LinkedList; | |
import java.util.Queue; | |
/** | |
* Author : Deepak Singhvi | |
*/ | |
public class StackUsingQueue { | |
private Queue<Integer> q1 = new LinkedList<>(); | |
private Queue<Integer> q2 = new LinkedList<>(); |
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.Stack; | |
/** | |
* Author: Deepak Singhvi | |
*/ | |
public class QueueUsingMultipleStack { | |
private Stack<Integer> s1 = new Stack<Integer>(); | |
private Stack<Integer> s2 = new Stack<Integer>(); |
NewerOlder