Skip to content

Instantly share code, notes, and snippets.

View deepaksinghvi's full-sized avatar
💭
Learning.....

Deepak Singhvi deepaksinghvi

💭
Learning.....
View GitHub Profile
@deepaksinghvi
deepaksinghvi / UnmixStrings.java
Created June 24, 2023 14:12
Unmix My Strings
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);
@deepaksinghvi
deepaksinghvi / LargestGap.java
Last active June 24, 2023 12:42
LargestGap
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;
/**
* Deepak Singhvi
*/
public class MaxLoot {
public static int maxLoot(int input[], int inputSize)
{
if (inputSize == 0)
return 0;
if (inputSize == 1)
return input[0];
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},
};
@deepaksinghvi
deepaksinghvi / StackDeque.java
Created May 1, 2019 14:45
Stack Implementation using Deque
/**
* 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);
@deepaksinghvi
deepaksinghvi / QueueDeque.java
Created May 1, 2019 14:45
Queue Implementation using Deque
/**
* 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);
/**
* Author: Deepak Singhvi
*/
class DequeueImpl {
private Deque head;
private Deque tail;
public DequeueImpl() {
}
/**
* Author: Deepak Singhvi
*/
class Deque {
private Integer data;
Deque next;
Deque prev;
public Integer getData() {
@deepaksinghvi
deepaksinghvi / StackUsingQueue.java
Created April 28, 2019 16:53
Stack Using Two Queues
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<>();
@deepaksinghvi
deepaksinghvi / QueueUsingMultipleStack.java
Created April 28, 2019 08:59
Queue Using Multiple Stacks
import java.util.Stack;
/**
* Author: Deepak Singhvi
*/
public class QueueUsingMultipleStack {
private Stack<Integer> s1 = new Stack<Integer>();
private Stack<Integer> s2 = new Stack<Integer>();