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()) | |
def wordCount(word): | |
global words | |
res = [item for item in words if item == word] | |
return len(res) | |
words = [input().strip() for i in range(N)] | |
N_Q = int(input().strip()) | |
query = [print (wordCount(input().strip())) for i in range(N_Q)] |
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 array_left_rotation(a, n, k): | |
if k % n == 0: | |
return a | |
else: | |
return (a[k%n: ] + a[ :k%n]) | |
n, k = map(int, input().strip().split(' ')) | |
a = list(map(int, input().strip().split(' '))) | |
answer = array_left_rotation(a, n, k); |
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 |
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 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
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
#!/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
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/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
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); | |
} |