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 sahil | |
*/ | |
import java.util.*; | |
public class FloorCeiling { | |
public static void main(String args[]){ | |
int arr[] = {5, 6, 8, 9, 6, 5, 5, 6}; | |
int x = 6; | |
ArrayList<Integer> result = findFloorCeiling(arr, x); |
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 Sahil Kadam | |
*/ | |
import java.util.*; | |
public class Node{ | |
String name; | |
Node left,right; | |
//ArrayList<String> subTree = new ArrayList<String>(); | |
Node(String name){ |
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.*; | |
public class findTriplets{ | |
public static void main(String []args){ | |
int[] input = {1, -2, -1, 0, 2}; | |
int result_n3 = findTriplets_n3(input); | |
int result_n2 = findTriplets_n2(input); | |
System.out.println(result_n3); | |
System.out.println(result_n2); | |
} |
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
#!/bin/python | |
import sys | |
a,b,c,d,e = input().strip().split(' ') | |
a,b,c,d,e = [int(a),int(b),int(c),int(d),int(e)] | |
lst = [a,b,c,d,e] |
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
n = int(input().strip()) | |
a = list(map(int, input().strip().split(' '))) | |
count = 0 | |
for i in range(len(a)): | |
swapCount = 0 | |
for j in range(len(a)-1): | |
if a[j] > a[j+1]: | |
temp = a[j] | |
a[j] = a[j+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
#!/bin/python3 | |
import sys | |
def checkPosition(lst, i, j, num): | |
if i == j and lst[i]>num: | |
return i-1 | |
if i == j and lst[i]<num: | |
return i | |
tmp = int((i+j)/2) |
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 MyQueue(object): | |
def __init__(self): | |
self.stack1 = [] | |
self.stack2 = [] | |
def peek(self): | |
if (len(self.stack2) == 0): | |
while(len(self.stack1) > 0): | |
self.stack2.append(self.stack1.pop()) | |
return self.stack2[len(self.stack2)-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
def is_matched(expression): | |
stack = [] | |
for item in expression: | |
if len(stack) == 0: | |
stack.append(item) | |
else: | |
if item == '{' or item == '[' or item == '(': | |
stack.append(item) | |
elif item == '}' and stack.pop() != '{': | |
return False |
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
""" | |
Detect a cycle in a linked list. Note that the head pointer may be 'None' if the list is empty. | |
A Node is defined as: | |
class Node(object): | |
def __init__(self, data = None, next_node = None): | |
self.data = data | |
self.next = next_node | |
""" |
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
def number_needed(a, b): | |
count = 0 | |
if len(a) >= len(b): | |
for i in range(len(b)): | |
if b[i] in a: | |
temp = list(a) | |
temp.remove(b[i]) | |
a = "".join(temp) | |
else: | |
count += 1 |
NewerOlder