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 circularQueue: | |
def __init__(self,size,arr): | |
# since python doesn`t have arrays i`m using list in place (by default a "list" is a linked list in python) | |
self.arr = arr | |
self.head=0 | |
self.tail=0 | |
self.size=size | |
def next(self,ptr): |
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 circularQueue: | |
def __init__(self,size): | |
# since python doesn`t have arrays i`m using list in place (by default a "list" is a linked list in python) | |
self.arr = [] | |
self.head=0 | |
self.tail=0 | |
self.size=size | |
for i in range(0,size): | |
self.arr.append(None) |
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.List; | |
import java.util.Arrays; | |
import java.util.ArrayList; | |
public class Main | |
{ | |
//O(n) | |
public static String twoSum(List numbers, int target){ | |
Integer head = 0, | |
tail = numbers.size()-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
import java.util.List; | |
import java.util.ArrayList; | |
public class Main | |
{ | |
public static int prefixSum(List<Integer> numbers, int head, int tail){ | |
List<Integer> factorialList = new ArrayList<>(); | |
Integer total = 0; | |
for(Integer e : numbers){ | |
total += 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.HashMap; | |
import java.util.Collections; | |
import java.util.Map; | |
public class Main | |
{ | |
public interface RepetitionChecker { | |
int SingleNumber(int[] sequence); | |
} |
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
#Linear solution O(n) | |
#Constant space | |
def uniqueNumber(sequence) -> int: | |
# flags which stores repeated numbers | |
# It works for 3 repetions only | |
once = 0 | |
twice = 0 | |
for num in sequence: |