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
/* Array Implementation of Stack */ | |
/* Author Vivek Singh */ | |
/* Last Modified on 19/7/2015 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
#define MAX_SIZE 101 | |
int A[MAX_SIZE]; | |
int TOP = -1; | |
void Push(int item) |
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 spiralOrder(A): | |
result = [] | |
T = 0 | |
B = len(A) - 1 | |
L = 0 | |
R = len(A[0]) -1 | |
dir = 0 | |
while T <= B and L <= R : | |
if dir == 0 : | |
for i in range(L, R+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 maxset(self, A): | |
maxSum = 0 | |
curretMaxSum = 0 | |
maxStart = 0 | |
maxEnd = 0 | |
currentStart = 0 | |
for i in range(len(A)) : | |
if A[i] >= 0 : | |
curretMaxSum += A[i] | |
if curretMaxSum > maxSum : |
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 generate(A): | |
triangle = [] | |
for rownum in range(A) : | |
nextValue = 1 | |
row = [nextValue] | |
for i in range(rownum) : | |
nextValue = nextValue * (rownum - i) * 1 / (i + 1) | |
row.append(nextValue) | |
triangle.append(row) | |
return triangle |
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 maxSubArray(A): | |
maxSumSoFar = 0 | |
currentMaxSum = 0 | |
for i in range(0, len(A)) : | |
currentMaxSum += A[i] | |
if currentMaxSum < 0 : | |
currentMaxSum = 0 | |
if maxSumSoFar < currentMaxSum : | |
maxSumSoFar = currentMaxSum | |
if maxSumSoFar == 0 and max(A) >= 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
def plusOne(A): | |
""" | |
:param A: List containing digits of a non - negative number | |
:return: List containing digits after addition of 1 | |
"""" | |
length = len(A) | |
number = 0 | |
i = length - 1 | |
while A[i] + 1 > 9 and i >= 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
def repeatedNumber(A): | |
""" | |
:param A: A tupple of integer | |
:return: Return a list [duplicate element , missing element] | |
""" | |
n = len(A) | |
dup = 0 | |
for i in range(len(A)) : | |
if A[abs(A[i]) - 1] > 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
__author__ = 'Vivek' | |
def comp(X, Y) : | |
""" | |
:param: X, Y two integers | |
:return : -1, 0 or 1 | |
""" | |
XY = str(X) + str(Y) | |
YX = str(Y) + str(X) | |
if XY < YX : | |
return -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
__author__ = 'Vivek' | |
def nextPermutation(A): | |
""" | |
:param: List of integer | |
:return : numerically next greater permutation of integers | |
""" | |
i = -1 | |
last = False | |
for k in range(len(A)-1) : | |
if A[k] < A[k+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
__author__ = 'Vivek' | |
#Returns smallest missing posistive integer in a list of integers | |
def divideArray(A) : | |
""" | |
:param: List of integers | |
:return: List having only positive integers | |
""" | |
j = 0 | |
for i in range(len(A)) : | |
if A[i] <= 0 : |
OlderNewer