├── .gitignore ├── 6sense ├── README.md └── findWordInGrid.py ├── Accenture └── README.md ├── Accolite ├── binaryArraySort.py ├── merge2SortedLinkedLists.py └── rotateLinkedListByKelements.py ├── Adobe ├── QuickSort.py ├── WinnerOfElection.py ├── checkIfStringsAreRotations.py ├── countOfInversionsArray.py └── parenthesisChecker.py ├── Amazon ├── DataEngineering │ └── README.md ├── Delete_Node_Without_HeadPointer.py ├── EquilibriumPointFirstOccurWhere.py ├── FindzeroSumSubArrays.py ├── ImplementSTRSTR.py ├── JosephusProblem.py ├── MaximumOfMinimumsOfAllWindowSizes.py ├── Possible_Words_Phone_Digits.py ├── countOfInversionsArray.py ├── getAggregationsByParsing.py ├── keypadTyping.py ├── merge2SortedLinkedLists.py ├── missingSmallestPositiveNumber.py ├── moveAllZerosToEndOfArray.py ├── parenthesisChecker.py ├── relativeSorting.py └── rotateLinkedListByKelements.py ├── AmericanExpress ├── README.md ├── problem01 │ ├── amex_hackerearth011.JPG │ ├── amex_hackerearth012.JPG │ └── amex_hackerearth013.JPG └── problem02 │ ├── amex_hackerearth02.JPG │ └── amex_hackerearth022.JPG ├── Athena-Health └── README.md ├── Betterworks ├── README.md └── print.py ├── Bloomberg └── moveAllZerosToEndOfArray.py ├── BrightMoney ├── Data_Analyst_Test.docx ├── Knapsack.py ├── LongestBalancedSubstring.py ├── README.md ├── countDistinctValidPANNumbers.py └── printSpirally.py ├── Busigence ├── README.md └── Vikas_Chitturi.ipynb ├── Byndr └── README.md ├── CloudCover └── README.md ├── Facebook └── ImplementSTRSTR.py ├── FactSet └── convertArrayToWave.py ├── Flipkart ├── addTwoNumbers_LinkedListRep.py ├── countOfInversionsArray.py └── parenthesisChecker.py ├── Fractal_Analytics ├── Arrays.md ├── Comparator.md ├── README.md ├── countChampNumbers.py ├── countOfAnagrams.py ├── numberOfGroups.py ├── sorting_words.md └── substrings.md ├── Fre8wise ├── README.md └── manipulate_string.py ├── Goldman-Sachs ├── convertArrayToWave.py ├── numberOfSquares_in_NbyN_CheesBoard.py ├── printNumbersContain123.py └── repeatingCharacter_LeftmostOccurrence.py ├── Google ├── First_Recurring_Character_In_String.py ├── allocateMinimumPages.py ├── checkPairsWithGivenSum.py └── maxIndexDiffOfArray.py ├── Grofers └── QuickSort.py ├── Guardant-Health ├── README.md ├── fallen_leaves.py └── maintainMinimumStartingNumber.py ├── HighRadius-Technologies └── README.md ├── Hike └── QuickSort.py ├── IQLECT ├── LargestPrimeFromSubsetSum.py └── README.md ├── InMobi └── README.md ├── Infrrd ├── problem01 │ ├── maximumRowsWithAll1s.py │ └── problem01.png └── problem02 │ ├── countMe.py │ └── problem02.png ├── Instabase ├── Add2BinaryStrings.py ├── README.md └── checkPairsWithGivenSum.py ├── Intuit ├── BuySellStock.py └── binaryArraySort.py ├── Kritikal-Solutions └── Delete_Without_Head_Pointer.py ├── LeadSquared ├── README.md ├── UniqueWaysToClimbStaircase.py ├── maximumSumLikeTimeCoefficients.py └── totalDistanceByStreetLights.py ├── MAQ_Software └── Closet0s1s2s.py ├── MakeMyTrip ├── rotateLinkedListByKelements.py └── sortedLinkedList012s.py ├── Mastek ├── README.md └── computedepth.sql ├── Microsoft ├── countOfInversionsArray.py ├── merge2SortedLinkedLists.py └── relativeSorting.py ├── Morgan-Stanley └── addTwoNumbers_LinkedListRep.py ├── Myntra ├── countOfInversionsArray.py └── removeDuplicatesSortedLinkedList.py ├── Nagarro └── isAnagram.py ├── OYO_Rooms ├── FindzeroSumSubArrays.py ├── parenthesisChecker.py └── removeDuplicatesSortedLinkedList.py ├── Oracle └── merge2SortedLinkedLists.py ├── Paytm ├── Convert_Infix_To_Postfix.py ├── binaryArraySort.py ├── frequencyLimitedRangeArrayElements.py └── subarrayWithZeroSum.py ├── Qalcomm ├── ImplementSTRSTR.py └── addTwoNumbers_LinkedListRep.py ├── Quikr └── BuySellStock.py ├── README.md ├── RelianceJIO ├── CamelCaseToSnakeCase.py ├── README.md └── getSmallestNumber.py ├── Salesforce └── BuySellStock.py ├── Samsung ├── merge2SortedLinkedLists.py ├── missingSmallestPositiveNumber.py └── moveAllZerosToEndOfArray.py ├── SkyPointCloud ├── README.md ├── binarySearch.py └── modifyString.py ├── Snapdeal └── addTwoNumbers_LinkedListRep.py ├── Swiggy └── README.md ├── SymphonyAI ├── README.md └── maximumHeightOfMudSegment.py ├── Tavant-Technologies └── README.md ├── Thomson-Reuters └── README.md ├── Thoughtworks ├── README.md └── ScheduleInterviews.py ├── Twilio ├── DiskSpaceAnalysis.py └── README.md ├── Uber ├── README.md └── getNewArray.py ├── Ushur ├── README.md └── findPairs.py ├── VMWare ├── Convert_Infix_To_Postfix.py ├── maxIndexDiffOfArray.py └── mergeKSortedLinkedLists.py ├── Vimeo └── README.md ├── Visa ├── addNode_DoublyLinkedList.py ├── populateList.py └── removeDuplicatesSortedLinkedList.py ├── Walmart ├── GroupAnagrams.py ├── minimumCoins.py └── minimumCoinsRecursive.py ├── Yahoo └── ThreeWayPartition.py ├── ZSAssociates ├── CrossSequence.py ├── OutputOfProgram.py └── OutputOfProgram2.py ├── Zoho ├── merge2SortedLinkedLists.py └── rearrangeArrayAlternately.py ├── Zycus └── README.md └── cimpress └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /6sense/README.md: -------------------------------------------------------------------------------- 1 | # Hackerrank Test (Personal Experience): 2 | -------------------------------------------------------------------------------- /6sense/findWordInGrid.py: -------------------------------------------------------------------------------- 1 | """ 2 | Refer below link for the question: 3 | https://www.geeksforgeeks.org/search-a-word-in-a-2d-grid-of-characters/ 4 | 5 | Solution: 6 | Algorithm for this is already present, but expected solution should 7 | have lowest time complexity (the algorithm should only traverse once unlike the 8 | solution above which traverses whole matrix for each word given) 9 | 10 | Enhancement: 11 | if the word is not present in the grid, print word along with row 12 | and col as (-1,-1) like word,-1,-1 13 | 14 | Hint: 15 | Use DP approach 16 | 17 | Solution that I have gone with is below: 18 | 19 | """ 20 | 21 | # Enter your code here. Read input from STDIN. Print output to STDOUT 22 | import sys 23 | class word_seek: 24 | 25 | def __init__(self): 26 | self.R = None 27 | self.C = None 28 | self.dir = [[-1, 0], [1, 0], [1, 1], 29 | [1, -1], [-1, -1], [-1, 1], 30 | [0, 1], [0, -1]] 31 | def search_grid(self, grid, row, col, word): 32 | if grid[row][col] != word[0]: 33 | return False 34 | for x, y in self.dir: 35 | rd, cd = row + x, col + y 36 | flag = True 37 | for k in range(1, len(word)): 38 | if (0 <= rd 1: 60 | tracker = sorted(tracker,key=lambda x: x[1],reverse=True) 61 | print (tracker[0][0],tracker[0][1],tracker[0][2]) 62 | return 63 | else: 64 | assert (tracker[0][1] == -1) and (tracker[0][2] == -1),"failed" 65 | print (tracker[0][0],tracker[0][1],tracker[0][2]) 66 | return 67 | 68 | if __name__ == '__main__': 69 | grid = sys.stdin.readlines() 70 | grid = [i.strip() for i in grid] 71 | ind = grid.index('') 72 | #grid = grid[:(ind)] 73 | #finders = grid[(ind+1):] 74 | #print (grid) 75 | #print (finders) 76 | wordSeek = word_seek() 77 | for w in grid[(ind+1):]: 78 | wordSeek.patternSearch(grid[:(ind)],w) -------------------------------------------------------------------------------- /Accenture/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process - Data Engineer - Round 1 (Skills Interview): 2 | + Can a python class have 2 __init__ methods? 3 | + Questions on class methods (staticmethods and classmethods). 4 | + Difference between method and function? 5 | + what are the ways in spark when writing data to storage to reduce or increase number of part files? 6 | + Difference between repartition and coalesce in Spark. 7 | + What is shuffle in spark? 8 | + can data be stored without indexes? 9 | + Object versioning in AWS S3? 10 | + Access contol policies in AWS S3 when creating a bucket? 11 | + Indexing in mongodb? 12 | + Given a small table with field names, write a sql query or spark code to get the required aggregation? refer Window functionality and ranking. 13 | + Differences between client mode and cluster mode (Spark execution) (https://stackoverflow.com/questions/37027732/apache-spark-differences-between-client-and-cluster-deploy-modes). 14 | + Machine learning - classification model - questions on model selection, model evaluation? 15 | + deploy a flask app in azure - what is the approach? 16 | + Questions on azure fundamentals? 17 | + what are the configurations for spark app when spark-submit is done? 18 | -------------------------------------------------------------------------------- /Accolite/binaryArraySort.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | N=int(input()) 8 | A=list(map(int,input().split())) 9 | 10 | binSort(A,N) 11 | 12 | for i in A: 13 | print(i,end=" ") 14 | print() 15 | 16 | T-=1 17 | if __name__ == "__main__": 18 | main() 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | #User function Template for python3 22 | ##Complete this function 23 | def binSort(arr, n): 24 | #Your code here 25 | 26 | 27 | ''' 28 | No need to print the array 29 | ''' 30 | c0 = arr.count(0) 31 | c1 = arr.count(1) 32 | for i in range(c0): 33 | arr[i] = 0 34 | for i in range(c0,c0+c1): 35 | arr[i] = 1 -------------------------------------------------------------------------------- /Accolite/merge2SortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | # Node Class 4 | class Node: 5 | def __init__(self, data): # data -> value stored in node 6 | self.data = data 7 | self.next = None 8 | # Linked List Class 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | # creates a new node with given value and appends it at the end of the linked list 13 | def append(self, new_value): 14 | new_node = Node(new_value) 15 | if self.head is None: 16 | self.head = new_node 17 | return 18 | curr_node = self.head 19 | while curr_node.next is not None: 20 | curr_node = curr_node.next 21 | curr_node.next = new_node 22 | # prints the elements of linked list starting with head 23 | def printList(self): 24 | if self.head is None: 25 | print(' ') 26 | return 27 | curr_node = self.head 28 | while curr_node: 29 | print(curr_node.data,end=" ") 30 | curr_node=curr_node.next 31 | print(' ') 32 | if __name__ == '__main__': 33 | t=int(input()) 34 | for cases in range(t): 35 | n,m = map(int, input().strip().split()) 36 | a = LinkedList() # create a new linked list 'a'. 37 | b = LinkedList() # create a new linked list 'b'. 38 | nodes_a = list(map(int, input().strip().split())) 39 | nodes_b = list(map(int, input().strip().split())) 40 | for x in nodes_a: 41 | a.append(x) 42 | for x in nodes_b: 43 | b.append(x) 44 | a.head = merge(a.head,b.head) 45 | a.printList() 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | #User function Template for python3 49 | ''' 50 | Function to merge two sorted lists in one 51 | using constant space. 52 | 53 | Function Arguments: head_a and head_b (head reference of both the sorted lists) 54 | Return Type: head of the obtained list after merger. 55 | { 56 | # Node Class 57 | class Node: 58 | def __init__(self, data): # data -> value stored in node 59 | self.data = data 60 | self.next = None 61 | } 62 | Contributed By: Nagendra Jha 63 | ''' 64 | def merge(head_a,head_b): 65 | #code here 66 | global a 67 | elements = [] 68 | curr_node = head_a 69 | while curr_node != None: 70 | elements.append(curr_node.data) 71 | curr_node = curr_node.next 72 | curr_node = head_b 73 | while curr_node != None: 74 | elements.append(curr_node.data) 75 | curr_node = curr_node.next 76 | elements = sorted(elements) 77 | a = LinkedList() 78 | for i in elements: 79 | a.append(i) 80 | return a.head -------------------------------------------------------------------------------- /Accolite/rotateLinkedListByKelements.py: -------------------------------------------------------------------------------- 1 | { 2 | class Node: 3 | def __init__(self, data): 4 | self.data = data 5 | self.next = None 6 | class LinkedList: 7 | def __init__(self): 8 | self.head = None 9 | def push(self, new_data): 10 | new_node = Node(new_data) 11 | new_node.next = self.head 12 | self.head = new_node 13 | def printList(self): 14 | temp = self.head 15 | while(temp): 16 | print(temp.data, end=" ") 17 | # arr.append(str(temp.data)) 18 | temp = temp.next 19 | print("") 20 | if __name__ == '__main__': 21 | start = LinkedList() 22 | t = int(input()) 23 | while(t > 0): 24 | llist = LinkedList() 25 | n = int(input()) 26 | values = list(map(int, input().strip().split())) 27 | for i in reversed(values): 28 | llist.push(i) 29 | k = int(input()) 30 | new_head = rotateList(llist.head, k) 31 | llist.head = new_head 32 | llist.printList() 33 | t -= 1 34 | # Contributed by: Harshit Sidhwa 35 | 36 | } 37 | ''' This is a function problem.You only need to complete the function given below ''' 38 | # Your task is to complete this function 39 | ''' 40 | class Node: 41 | def __init__(self, data): 42 | self.data = data 43 | self.next = None 44 | ''' 45 | # This function should rotate list counter- 46 | # clockwise by k and return new head (if changed) 47 | def rotateList(head, k): 48 | # code here 49 | global llist 50 | llist = LinkedList() 51 | C = 0 52 | curr_node = head 53 | part1 = [] 54 | part2 = [] 55 | while curr_node != None: 56 | if C <= k-1: 57 | part1.append(curr_node.data) 58 | elif C > k-1: 59 | part2.append(curr_node.data) 60 | C += 1 61 | curr_node = curr_node.next 62 | total = reversed(part2 + part1) 63 | for i in total: 64 | llist.push(i) 65 | return llist.head -------------------------------------------------------------------------------- /Adobe/QuickSort.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | if __name__ == "__main__": 4 | t=int(input()) 5 | for i in range(t): 6 | n=int(input()) 7 | arr=list(map(int,input().split())) 8 | quickSort(arr,0,n-1) 9 | for i in range(n): 10 | print(arr[i],end=" ") 11 | print() 12 | 13 | } 14 | ''' This is a function problem.You only need to complete the function given below ''' 15 | #User function Template for python3 16 | def quickSort(arr,low,high): 17 | if low < high: 18 | 19 | # pi is partitioning index, arr[p] is now 20 | # at right place 21 | pi = partition(arr,low,high) 22 | 23 | # Separately sort elements before 24 | # partition and after partition 25 | quickSort(arr, low, pi-1) 26 | quickSort(arr, pi+1, high) 27 | 28 | def partition(arr,low,high): 29 | #add code here 30 | tmp = 0 31 | pivot = arr[high] 32 | i = low - 1 33 | for j in range(low,high): 34 | if arr[j] <= pivot: 35 | i += 1 36 | tmp = arr[i] 37 | arr[i] = arr[j] 38 | arr[j] = tmp 39 | tmp = arr[i+1] 40 | arr[i+1] = arr[high] 41 | arr[high] = tmp 42 | return i+1 -------------------------------------------------------------------------------- /Adobe/WinnerOfElection.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | arr=input().strip().split() 10 | 11 | winner(arr,n) 12 | print() 13 | 14 | T-=1 15 | if __name__=="__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | #Complete this function 21 | def winner(arr,n): 22 | #Your code here 23 | import collections 24 | votes = collections.Counter(arr) 25 | maxVotes = max(votes.values()) 26 | if len(set(votes.values())) != len(votes.values()): 27 | maxVoteNames = [] 28 | for k,v in votes.items(): 29 | if v == maxVotes: 30 | maxVoteNames.append(k) 31 | print (min(maxVoteNames),maxVotes,end="") 32 | else: 33 | for k,v in votes.items(): 34 | if v == maxVotes: 35 | print (k,maxVotes,end="") 36 | return -------------------------------------------------------------------------------- /Adobe/checkIfStringsAreRotations.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__=='__main__': 14 | t = int(input()) 15 | for i in range(t): 16 | s1=str(input()) 17 | s2=str(input()) 18 | if(areRotations(s1,s2)): 19 | print(1) 20 | else: 21 | print(0) 22 | 23 | 24 | } 25 | ''' This is a function problem.You only need to complete the function given below ''' 26 | #User function Template for python3 27 | ''' 28 | Your task is tocheck if the given two strings 29 | are rotations of each other. 30 | Function Arguments: s1 and s2 (given strings) 31 | Return Type:boolean 32 | ''' 33 | def areRotations(s1,s2): 34 | if (len(s1) == 1 or len(s2) == 1) & (s1 != s2): 35 | return False 36 | #code here 37 | if (len(s1) == len(s2)) & (set(s1)==set(s2)) & (s2 in s1+s2) & (s1 in s1+s2): 38 | return True 39 | else: 40 | return False -------------------------------------------------------------------------------- /Adobe/countOfInversionsArray.py: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks Code - Copied# 2 | { 3 | #Initial Template for Python 3 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__=='__main__': 15 | t = int(input()) 16 | for tt in range(t): 17 | n = int(input()) 18 | a = list(map(int, input().strip().split())) 19 | print(Inversion_Count(a,n)) 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ''' 24 | Your task is to return total number of inversions 25 | present in the array. 26 | 27 | Function Arguments: array a and size n 28 | Return Type: Integer 29 | ''' 30 | def Inversion_Count(arr,n): 31 | if a == sorted(a): 32 | return 0 33 | temp_arr = [0]*n 34 | return mergesort(arr,temp_arr,0,n-1) 35 | 36 | def mergesort(arr,temp_arr,left,right): 37 | inv_count = 0 38 | if left < right: 39 | mid = (left + right)//2 40 | inv_count = mergesort(arr,temp_arr,left,mid) 41 | inv_count += mergesort(arr,temp_arr,mid+1,right) 42 | inv_count += merge(arr,temp_arr,left,mid,right) 43 | return inv_count 44 | 45 | def merge(arr,temp_arr,left, mid, right): 46 | # Merge the temp arrays back into arr[l..r] 47 | i = left # Initial index of first subarray 48 | j = mid+1 # Initial index of second subarray 49 | k = left # Initial index of merged subarray 50 | invcount = 0 51 | while i <= mid and j <= right: 52 | if arr[i] <= arr[j]: 53 | temp_arr[k] = arr[i] 54 | i += 1 55 | else: 56 | temp_arr[k] = arr[j] 57 | invcount += (mid - i + 1) 58 | j += 1 59 | k += 1 60 | # Copy the remaining elements of L[], if there 61 | # are any 62 | while i <= mid: 63 | temp_arr[k] = arr[i] 64 | i += 1 65 | k += 1 66 | # Copy the remaining elements of R[], if there 67 | # are any 68 | while j <= right: 69 | temp_arr[k] = arr[j] 70 | j += 1 71 | k += 1 72 | 73 | for lr in range(left, right + 1): 74 | arr[lr] = temp_arr[lr] 75 | return invcount 76 | -------------------------------------------------------------------------------- /Adobe/parenthesisChecker.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | #Contributed by : Nagendra Jha 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__ == '__main__': 15 | test_cases = int(input()) 16 | for cases in range(test_cases) : 17 | #n = int(input()) 18 | #n,k = map(int,imput().strip().split()) 19 | #a = list(map(int,input().strip().split())) 20 | s = str(input()) 21 | if ispar(s): 22 | print("balanced") 23 | else: 24 | print("not balanced") 25 | } 26 | ''' This is a function problem.You only need to complete the function given below ''' 27 | #User function Template for python3 28 | ''' 29 | Function Arguments : 30 | @param : s (given string containing parenthesis) 31 | @return : boolean True or False 32 | ''' 33 | 34 | def isMatchingPair(c1,c2): 35 | if (c1=='(') & (c2==')'): 36 | return True 37 | elif (c1=='{') & (c2=='}'): 38 | return True 39 | elif (c1=='[') & (c2==']'): 40 | return True 41 | else: 42 | return False 43 | 44 | def ispar(s): 45 | # code here 46 | import queue 47 | stack = queue.LifoQueue() 48 | 49 | for i in range(len(s)): 50 | if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')): 51 | stack.put(s[i]) 52 | if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')): 53 | if stack.empty(): 54 | return False 55 | elif not isMatchingPair(stack.get(),s[i]): 56 | return False 57 | 58 | if stack.empty(): 59 | return True 60 | else: 61 | return False -------------------------------------------------------------------------------- /Amazon/DataEngineering/README.md: -------------------------------------------------------------------------------- 1 | # Data Engineering Assessment (As of Oct 2024): 2 | + Assessment redirected to Hackerank from Amazon Jobs profile configuration. 3 | + Assessment with a maximum duration of 120 mins. 4 | + Multiple Choice Questions on Very basic SQL (Joins, MySQL syntax, Error recognition etc..). Around 20 MCQs. 5 | + 3 SQL coding questions, Easy, Medium and Hard [Simple Joins to writing subqueries to ranking + CTEs + Computing Aggregate metrics + subqueries] 6 | -------------------------------------------------------------------------------- /Amazon/Delete_Node_Without_HeadPointer.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | def __init__(self,dataVal,nextNode=None): 3 | self.data = dataVal 4 | self.next = nextNode 5 | 6 | def getData(self): 7 | return (self.data) 8 | 9 | def setData(self,val): 10 | self.data = val 11 | 12 | def getNextNode(self): 13 | return (self.next) 14 | 15 | def setNextNode(self,val): 16 | self.next = val 17 | 18 | class LinkedList(object): 19 | def __init__(self,head=None): 20 | self.head = head 21 | self.size = 0 22 | 23 | def getSize(self): 24 | return (self.size) 25 | 26 | def addNode(self,data): 27 | newNode = Node(data) 28 | newNode.setNextNode(self.head) 29 | self.head = newNode 30 | self.size += 1 31 | return True 32 | 33 | def printNode(self): 34 | curr = self.head 35 | while curr: 36 | print (curr.data) 37 | curr = curr.getNextNode() 38 | 39 | def deleteNode(self,value): 40 | 41 | prev = None 42 | curr = self.head 43 | while curr: 44 | if curr.data == value: 45 | if prev: 46 | prev.setNextNode(curr.getNextNode()) 47 | else: 48 | self.head = curr.getNextNode() 49 | self.size -= 1 50 | return True 51 | 52 | prev = curr 53 | curr = curr.getNextNode() 54 | 55 | return False 56 | 57 | 58 | myList = LinkedList() 59 | print (myList.getSize()) 60 | print ("______*Inserting*_______") 61 | 62 | myList.addNode(5) 63 | myList.addNode(10) 64 | myList.addNode(15) 65 | myList.addNode(20) 66 | myList.addNode(25) 67 | 68 | print ("printing") 69 | myList.printNode() 70 | 71 | print ("Deleting") 72 | myList.deleteNode(10) 73 | myList.deleteNode(20) 74 | myList.deleteNode(5) 75 | 76 | myList.addNode(90) 77 | myList.addNode(2000) 78 | print (myList.getSize()) 79 | myList.printNode() -------------------------------------------------------------------------------- /Amazon/EquilibriumPointFirstOccurWhere.py: -------------------------------------------------------------------------------- 1 | { 2 | # Initial Template for Python 3 3 | import math 4 | def main(): 5 | T = int(input()) 6 | while(T > 0): 7 | N = int(input()) 8 | A = [int(x) for x in input().strip().split()] 9 | print(equilibriumPoint(A, N)) 10 | T -= 1 11 | if __name__ == "__main__": 12 | main() 13 | 14 | } 15 | ''' This is a function problem.You only need to complete the function given below ''' 16 | # User function Template for python3 17 | # Complete this function 18 | def equilibriumPoint(A, N): 19 | # Your code here 20 | if len(A)==1: 21 | return 1 22 | else: 23 | eqlist = [] 24 | for i in range(1,N-1): 25 | if sum(A[:i]) == sum(A[i+1:]): 26 | eqlist.append(i+1) 27 | if sum(A[1:]) == 0: 28 | eqlist.insert(0,1) 29 | if sum(A[:N-1]) == 0: 30 | eqlist.append(N) 31 | if eqlist: 32 | return min(eqlist) 33 | else: 34 | return -1 -------------------------------------------------------------------------------- /Amazon/FindzeroSumSubArrays.py: -------------------------------------------------------------------------------- 1 | def subArrayExists(arr,n): 2 | ##Your code here 3 | hashMap = {} 4 | out = [] 5 | sum1 = 0 6 | for i in range(n): 7 | sum1 += arr[i] 8 | if sum1==0: 9 | out.append((0,i)) 10 | al = [] 11 | if sum1 in hashMap: 12 | al = hashMap.get(sum1) 13 | for it in range(len(al)): 14 | out.append((al[it]+1,i)) 15 | al.append(i) 16 | hashMap[sum1] = al 17 | return len(out) 18 | 19 | 20 | if __name__ == '__main__': 21 | t = int(input()) 22 | for tcase in range(t): 23 | n = int(input()) 24 | arr = list(map(int,input().strip().split())) 25 | print (subArrayExists(arr,n)) -------------------------------------------------------------------------------- /Amazon/ImplementSTRSTR.py: -------------------------------------------------------------------------------- 1 | { 2 | #Contributed by : Nagendra Jha 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__ == '__main__': 14 | t=int(input()) 15 | for cases in range(t): 16 | s,p =input().strip().split() 17 | print(strstr(s,p)) 18 | 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | ''' 22 | Your task is to return the index of the pattern 23 | present in the given string. 24 | 25 | Function Arguments: s (given text), p(given pattern) 26 | Return Type: Integer. 27 | 28 | ''' 29 | def strstr(s,p): 30 | #code here 31 | import re 32 | loc = re.search(p,s) 33 | if loc is not None: 34 | return (loc.start()) 35 | else: 36 | return -1 -------------------------------------------------------------------------------- /Amazon/JosephusProblem.py: -------------------------------------------------------------------------------- 1 | { 2 | import math 3 | //Position this line where user code will be pasted. 4 | 5 | def main(): 6 | 7 | T=int(input()) 8 | 9 | while(T>0): 10 | 11 | 12 | nk=[int(x) for x in input().strip().split()] 13 | n=nk[0] 14 | k=nk[1] 15 | 16 | print(josephus(n,k)) 17 | 18 | T-=1 19 | if __name__=="__main__": 20 | main() 21 | } 22 | ''' This is a function problem.You only need to complete the function given below ''' 23 | #Complete this function 24 | def josephus(n,k): 25 | #Your code here 26 | if n == 1: 27 | return n 28 | return ((josephus(n-1,k)+k-1)%n + 1) -------------------------------------------------------------------------------- /Amazon/MaximumOfMinimumsOfAllWindowSizes.py: -------------------------------------------------------------------------------- 1 | #User function Template for python3 2 | """ 3 | Given an integer array A[] of size N. The task is to find the maximum of the minimum of every window size in the array. 4 | Note: Window size varies from 1 to n. 5 | 6 | Input: 7 | The first line contains an integer T denoting the total number of test cases. In each test cases, the first line contains an integer N denoting the size of array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. 8 | 9 | Output: 10 | In each seperate line, print the array of numbers of size N for each of the considered window size 1, 2 , ..., N respectively. 11 | 12 | User Task: 13 | The task is to complete the function printMaxOfMin() which finds the maximum of minimum of every window size. 14 | 15 | Constraints: 16 | 1 <= T <= 50 17 | 1 <= N <= 10^5 18 | 1 <= A[i] <= 10^6 19 | 20 | Example: 21 | Input: 22 | 2 23 | 7 24 | 10 20 30 50 10 70 30 25 | 3 26 | 10 20 30 27 | Output: 28 | 70 30 20 10 10 10 10 29 | 30 20 10 30 | 31 | Explaination: 32 | Testcase 1: 33 | First element in output indicates maximum of minimums of all windows of size 1. Minimums of windows of size 1 are {10}, {20}, {30}, {50}, {10}, {70} and {30}. Maximum of these minimums is 70. 34 | Second element in output indicates maximum of minimums of all windows of size 2. Minimums of windows of size 2 are {10}, {20}, {30}, {10}, {10}, and {30}. Maximum of these minimums is 30. 35 | Third element in output indicates maximum of minimums of all windows of size 3. Minimums of windows of size 3 are {10}, {20}, {10}, {10} and {10}. Maximum of these minimums is 20. 36 | Similarly other elements of output are computed. 37 | Testcase 2: First element in output indicates maximum of minimums of all windows of size 1.Minimums of windows of size 1 are {10} , {20} , {30}. Maximum of these minimums are 30 and similarly other outputs can be computed. 38 | """ 39 | ''' 40 | Function Arguments : 41 | @param : a(given array), n (size of array) 42 | @return : None, print the required Maxofmin array. 43 | ''' 44 | 45 | def printMaxOfMin(a,n): 46 | # code here 47 | s = [] 48 | left = [0 for i in range(n+1)] 49 | right = [0 for i in range(n+1)] 50 | left[:n] = [-1]*n 51 | right[:n] = [n]*n 52 | for i in range(0,n): 53 | while (len(s) != 0 and a[s[-1]] >= a[i]): 54 | s.pop() 55 | if (len(s) != 0): 56 | left[i] = s[-1] 57 | s.append(i) 58 | while (len(s) != 0): 59 | s.pop() 60 | for i in range(n-1,-1,-1): 61 | while (len(s) != 0 and a[s[-1]] >= a[i]): 62 | s.pop() 63 | if (len(s) != 0): 64 | right[i] = s[-1] 65 | s.append(i) 66 | ans = [0]*(n+1) 67 | for i in range(0,n): 68 | length = right[i] - left[i] - 1 69 | ans[length] = max(ans[length],a[i]) 70 | for i in range(n-1,0,-1): 71 | ans[i] = max(ans[i],ans[i+1]) 72 | for i in range(1,n+1): 73 | print (ans[i],end=" ") 74 | print ("") 75 | #{ 76 | # Driver Code Starts 77 | #Initial Template for Python 3 78 | 79 | import atexit 80 | import io 81 | import sys 82 | 83 | #Contributed by : Nagendra Jha 84 | 85 | _INPUT_LINES = sys.stdin.read().splitlines() 86 | input = iter(_INPUT_LINES).__next__ 87 | _OUTPUT_BUFFER = io.StringIO() 88 | sys.stdout = _OUTPUT_BUFFER 89 | 90 | @atexit.register 91 | 92 | def write(): 93 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 94 | 95 | if __name__ == '__main__': 96 | test_cases = int(input()) 97 | for cases in range(test_cases) : 98 | n = int(input()) 99 | a = list(map(int,input().strip().split())) 100 | printMaxOfMin(a,n) 101 | 102 | # } Driver Code Ends -------------------------------------------------------------------------------- /Amazon/Possible_Words_Phone_Digits.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | 6 | T=int(input()) 7 | 8 | while(T>0): 9 | 10 | N=int(input()) 11 | a=[int(x) for x in input().strip().split()] 12 | 13 | possibleWords(a,N) 14 | 15 | print() 16 | 17 | T-=1 18 | if __name__=="__main__": 19 | main() 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ##Complete this function 24 | def possibleWords(a,N): 25 | ##Your code here 26 | import itertools 27 | ph = {'abc':2,'def':3,'ghi':4,'jkl':5,'mno':6,'pqrs':7,'tuv':8,'wxyz':9} 28 | my_sts = [] 29 | for x in a: 30 | for k,v in ph.items(): 31 | if v == x: 32 | my_sts.append(k) 33 | if len(my_sts)>1: 34 | res = list(itertools.product(*my_sts)) 35 | res = [''.join(u) for u in res] 36 | print (' '.join(i for i in res)) 37 | else: 38 | print (' '.join(list(my_sts[0]))) -------------------------------------------------------------------------------- /Amazon/countOfInversionsArray.py: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks Code - Copied# 2 | { 3 | #Initial Template for Python 3 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__=='__main__': 15 | t = int(input()) 16 | for tt in range(t): 17 | n = int(input()) 18 | a = list(map(int, input().strip().split())) 19 | print(Inversion_Count(a,n)) 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ''' 24 | Your task is to return total number of inversions 25 | present in the array. 26 | 27 | Function Arguments: array a and size n 28 | Return Type: Integer 29 | ''' 30 | def Inversion_Count(arr,n): 31 | if a == sorted(a): 32 | return 0 33 | temp_arr = [0]*n 34 | return mergesort(arr,temp_arr,0,n-1) 35 | 36 | def mergesort(arr,temp_arr,left,right): 37 | inv_count = 0 38 | if left < right: 39 | mid = (left + right)//2 40 | inv_count = mergesort(arr,temp_arr,left,mid) 41 | inv_count += mergesort(arr,temp_arr,mid+1,right) 42 | inv_count += merge(arr,temp_arr,left,mid,right) 43 | return inv_count 44 | 45 | def merge(arr,temp_arr,left, mid, right): 46 | # Merge the temp arrays back into arr[l..r] 47 | i = left # Initial index of first subarray 48 | j = mid+1 # Initial index of second subarray 49 | k = left # Initial index of merged subarray 50 | invcount = 0 51 | while i <= mid and j <= right: 52 | if arr[i] <= arr[j]: 53 | temp_arr[k] = arr[i] 54 | i += 1 55 | else: 56 | temp_arr[k] = arr[j] 57 | invcount += (mid - i + 1) 58 | j += 1 59 | k += 1 60 | # Copy the remaining elements of L[], if there 61 | # are any 62 | while i <= mid: 63 | temp_arr[k] = arr[i] 64 | i += 1 65 | k += 1 66 | # Copy the remaining elements of R[], if there 67 | # are any 68 | while j <= right: 69 | temp_arr[k] = arr[j] 70 | j += 1 71 | k += 1 72 | 73 | for lr in range(left, right + 1): 74 | arr[lr] = temp_arr[lr] 75 | return invcount 76 | -------------------------------------------------------------------------------- /Amazon/getAggregationsByParsing.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3.9 2 | # Asked in Thrasio Interview Process 3 | # Input: 4 | 5 | sales_data = [{'channel':'Amazon', 'id':'AMZ456', 'sales':10, 'returns':0}, 6 | {'channel':'Amazon', 'id':'AMZ123', 'sales':5, 'returns':2}, 7 | {'channel':'Shopify', 'id':'1234', 'sales':15, 'returns':0}, 8 | {'channel':'Target', 'id':'TGT456', 'sales':23, 'returns':5} 9 | ] 10 | 11 | channel_thrasio_mapping = { 12 | 'AMAZON':{'AMZ123':'THRASIO-987', 'AMZ456':'THRASIO-456'}, 13 | 'SHOPIFY':{'1234':'THRASIO-987', '5678':'THRASIO-321'} 14 | } 15 | 16 | #Expected Output: 17 | # [ 18 | # {'id':'THRASIO-987', 'net_sales':18, 'returns':2}, 19 | # {'id':'THRASIO-456', 'net_sales':10, 'returns':0}, 20 | # ] 21 | 22 | result = [] 23 | for k1,v1 in channel_thrasio_mapping.items(): 24 | for k2,v2 in v1.items(): 25 | temp_dict = {} 26 | temp_dict['id'] = v2 27 | all_sales = [] 28 | all_returns = [] 29 | for s in sales_data: 30 | if s['id'] == k2: 31 | all_sales.append(s['sales']) 32 | all_returns.append(s['returns']) 33 | net_sales = sum(all_sales)-sum(all_returns) 34 | returns = sum(all_returns) 35 | temp_dict['net_sales'] = net_sales 36 | temp_dict['returns'] = returns 37 | result.append(temp_dict) 38 | 39 | 40 | #print (result) 41 | unique_thrasio_ids = set([t['id'] for t in result]) 42 | #print (unique_thrasio_ids) 43 | 44 | output = [] 45 | for utd in unique_thrasio_ids: 46 | final_result = {} 47 | final_result['id'] = utd 48 | final_result['net_sales'] = 0 49 | final_result['returns'] = 0 50 | for res in result: 51 | if res['id'] == utd: 52 | final_result['net_sales'] += res['net_sales'] 53 | final_result['returns'] += res['returns'] 54 | output.append(final_result) 55 | 56 | print (output) 57 | -------------------------------------------------------------------------------- /Amazon/keypadTyping.py: -------------------------------------------------------------------------------- 1 | def keypadTyping(s): 2 | for c in s: 3 | print (mydict[c],end="") 4 | 5 | if __name__ == '__main__': 6 | t = int(input()) 7 | mydict = {'a':2,'b':2,'c':2, 8 | 'd':3,'e':3,'f':3, 9 | 'g':4,'h':4,'i':4, 10 | 'j':5,'k':5,'l':5, 11 | 'm':6,'n':6,'o':6, 12 | 'p':7,'q':7,'r':7,'s':7, 13 | 't':8,'u':8,'v':8, 14 | 'w':9,'x':9,'y':9,'z':9} 15 | for tcase in range(t): 16 | s = input() 17 | keypadTyping(s) 18 | print () -------------------------------------------------------------------------------- /Amazon/merge2SortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | # Node Class 4 | class Node: 5 | def __init__(self, data): # data -> value stored in node 6 | self.data = data 7 | self.next = None 8 | # Linked List Class 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | # creates a new node with given value and appends it at the end of the linked list 13 | def append(self, new_value): 14 | new_node = Node(new_value) 15 | if self.head is None: 16 | self.head = new_node 17 | return 18 | curr_node = self.head 19 | while curr_node.next is not None: 20 | curr_node = curr_node.next 21 | curr_node.next = new_node 22 | # prints the elements of linked list starting with head 23 | def printList(self): 24 | if self.head is None: 25 | print(' ') 26 | return 27 | curr_node = self.head 28 | while curr_node: 29 | print(curr_node.data,end=" ") 30 | curr_node=curr_node.next 31 | print(' ') 32 | if __name__ == '__main__': 33 | t=int(input()) 34 | for cases in range(t): 35 | n,m = map(int, input().strip().split()) 36 | a = LinkedList() # create a new linked list 'a'. 37 | b = LinkedList() # create a new linked list 'b'. 38 | nodes_a = list(map(int, input().strip().split())) 39 | nodes_b = list(map(int, input().strip().split())) 40 | for x in nodes_a: 41 | a.append(x) 42 | for x in nodes_b: 43 | b.append(x) 44 | a.head = merge(a.head,b.head) 45 | a.printList() 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | #User function Template for python3 49 | ''' 50 | Function to merge two sorted lists in one 51 | using constant space. 52 | 53 | Function Arguments: head_a and head_b (head reference of both the sorted lists) 54 | Return Type: head of the obtained list after merger. 55 | { 56 | # Node Class 57 | class Node: 58 | def __init__(self, data): # data -> value stored in node 59 | self.data = data 60 | self.next = None 61 | } 62 | Contributed By: Nagendra Jha 63 | ''' 64 | def merge(head_a,head_b): 65 | #code here 66 | global a 67 | elements = [] 68 | curr_node = head_a 69 | while curr_node != None: 70 | elements.append(curr_node.data) 71 | curr_node = curr_node.next 72 | curr_node = head_b 73 | while curr_node != None: 74 | elements.append(curr_node.data) 75 | curr_node = curr_node.next 76 | elements = sorted(elements) 77 | a = LinkedList() 78 | for i in elements: 79 | a.append(i) 80 | return a.head -------------------------------------------------------------------------------- /Amazon/missingSmallestPositiveNumber.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | 12 | print(missingNumber(arr,n)) 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | ##Complete this function 21 | def missingNumber(arr,n): 22 | #Your code here 23 | poss = [x for x in arr if x > 0] 24 | if poss: 25 | if poss == list(range(1,n+1)): 26 | return max(poss)+1 27 | else: 28 | min_poss = min(poss) 29 | max_poss = max(poss) 30 | total_range = list(range(1,max_poss+1)) 31 | missingNumbers = set(total_range) - set(poss) 32 | return min(missingNumbers) 33 | else: 34 | return 0 -------------------------------------------------------------------------------- /Amazon/moveAllZerosToEndOfArray.py: -------------------------------------------------------------------------------- 1 | def moveZerosToEnd(arr): 2 | arr_0 = [x for x in arr if x!=0] 3 | zeros = [0] * (len(arr)-len(arr_0)) 4 | ans = arr_0 + zeros 5 | return " ".join(str(u) for u in ans) 6 | 7 | if __name__ == '__main__': 8 | T = int(input()) 9 | for t in range(T): 10 | N = int(input()) 11 | arr = list(map(int,input().strip().split())) 12 | print (moveZerosToEnd(arr)) -------------------------------------------------------------------------------- /Amazon/parenthesisChecker.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | #Contributed by : Nagendra Jha 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__ == '__main__': 15 | test_cases = int(input()) 16 | for cases in range(test_cases) : 17 | #n = int(input()) 18 | #n,k = map(int,imput().strip().split()) 19 | #a = list(map(int,input().strip().split())) 20 | s = str(input()) 21 | if ispar(s): 22 | print("balanced") 23 | else: 24 | print("not balanced") 25 | } 26 | ''' This is a function problem.You only need to complete the function given below ''' 27 | #User function Template for python3 28 | ''' 29 | Function Arguments : 30 | @param : s (given string containing parenthesis) 31 | @return : boolean True or False 32 | ''' 33 | 34 | def isMatchingPair(c1,c2): 35 | if (c1=='(') & (c2==')'): 36 | return True 37 | elif (c1=='{') & (c2=='}'): 38 | return True 39 | elif (c1=='[') & (c2==']'): 40 | return True 41 | else: 42 | return False 43 | 44 | def ispar(s): 45 | # code here 46 | import queue 47 | stack = queue.LifoQueue() 48 | 49 | for i in range(len(s)): 50 | if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')): 51 | stack.put(s[i]) 52 | if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')): 53 | if stack.empty(): 54 | return False 55 | elif not isMatchingPair(stack.get(),s[i]): 56 | return False 57 | 58 | if stack.empty(): 59 | return True 60 | else: 61 | return False -------------------------------------------------------------------------------- /Amazon/relativeSorting.py: -------------------------------------------------------------------------------- 1 | def relativeSorting(A1,A2): 2 | common_elements = set(A1).intersection(set(A2)) 3 | extra = set(A1).difference(set(A2)) 4 | out = [] 5 | for i in A2: 6 | s = [i] * A1.count(i) 7 | out.extend(s) 8 | extra_out = [] 9 | for j in extra: 10 | u = [j] * A1.count(j) 11 | extra_out.extend(u) 12 | out = out + sorted(extra_out) 13 | return " ".join(str(i) for i in out) 14 | 15 | if __name__ == '__main__': 16 | t = int(input()) 17 | for tcase in range(t): 18 | N,M = list(map(int,input().strip().split())) 19 | A1 = list(map(int,input().strip().split())) 20 | A2 = list(map(int,input().strip().split())) 21 | print (relativeSorting(A1,A2)) -------------------------------------------------------------------------------- /Amazon/rotateLinkedListByKelements.py: -------------------------------------------------------------------------------- 1 | { 2 | class Node: 3 | def __init__(self, data): 4 | self.data = data 5 | self.next = None 6 | class LinkedList: 7 | def __init__(self): 8 | self.head = None 9 | def push(self, new_data): 10 | new_node = Node(new_data) 11 | new_node.next = self.head 12 | self.head = new_node 13 | def printList(self): 14 | temp = self.head 15 | while(temp): 16 | print(temp.data, end=" ") 17 | # arr.append(str(temp.data)) 18 | temp = temp.next 19 | print("") 20 | if __name__ == '__main__': 21 | start = LinkedList() 22 | t = int(input()) 23 | while(t > 0): 24 | llist = LinkedList() 25 | n = int(input()) 26 | values = list(map(int, input().strip().split())) 27 | for i in reversed(values): 28 | llist.push(i) 29 | k = int(input()) 30 | new_head = rotateList(llist.head, k) 31 | llist.head = new_head 32 | llist.printList() 33 | t -= 1 34 | # Contributed by: Harshit Sidhwa 35 | 36 | } 37 | ''' This is a function problem.You only need to complete the function given below ''' 38 | # Your task is to complete this function 39 | ''' 40 | class Node: 41 | def __init__(self, data): 42 | self.data = data 43 | self.next = None 44 | ''' 45 | # This function should rotate list counter- 46 | # clockwise by k and return new head (if changed) 47 | def rotateList(head, k): 48 | # code here 49 | global llist 50 | llist = LinkedList() 51 | C = 0 52 | curr_node = head 53 | part1 = [] 54 | part2 = [] 55 | while curr_node != None: 56 | if C <= k-1: 57 | part1.append(curr_node.data) 58 | elif C > k-1: 59 | part2.append(curr_node.data) 60 | C += 1 61 | curr_node = curr_node.next 62 | total = reversed(part2 + part1) 63 | for i in total: 64 | llist.push(i) 65 | return llist.head -------------------------------------------------------------------------------- /AmericanExpress/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process for Engineer - II (2021) (Personal): 2 | ### First Round - Coding Round: Online Coding Round with time management. 3 | ### Second Round - Design: 4 | + Design an Application that serves machine learning model results in real-time (Design a feedback ingestion system and notifications pusher) - Brush upon 5 | system design concepts, NoSQL Databases, caching, load balancer frameworks, distributed computing fundamentals, APIs, software design patterns. 6 | 7 | ### Third Round - Technical: 8 | + Implement KNN (K-Nearest neighbors) algorithm at scale - Start from scratch - Try to think of solution that doesn't rely on existing cluster computing frameworks 9 | like spark, Dask etc - performance and efficient design matters! - very good question, completely depends on the distributed and parallel processing paradigms and 10 | operating systems knowledge. 11 | -------------------------------------------------------------------------------- /AmericanExpress/problem01/amex_hackerearth011.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/AmericanExpress/problem01/amex_hackerearth011.JPG -------------------------------------------------------------------------------- /AmericanExpress/problem01/amex_hackerearth012.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/AmericanExpress/problem01/amex_hackerearth012.JPG -------------------------------------------------------------------------------- /AmericanExpress/problem01/amex_hackerearth013.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/AmericanExpress/problem01/amex_hackerearth013.JPG -------------------------------------------------------------------------------- /AmericanExpress/problem02/amex_hackerearth02.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/AmericanExpress/problem02/amex_hackerearth02.JPG -------------------------------------------------------------------------------- /AmericanExpress/problem02/amex_hackerearth022.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/AmericanExpress/problem02/amex_hackerearth022.JPG -------------------------------------------------------------------------------- /Athena-Health/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process for SMTS (Senior Member of Technical Staff) - 2021: 2 | ### First Round - Coding (Data Structures and Algorithms): 3 | + Given an array with 0s, 1s and 2s - sort the array without actually doing sorting (Incase of python - Avoid using built-in functions for any operations). 4 | + Given an unsorted array, Find the median of the given array (Do not use any libraries and functions, Raw code has to be written). 5 | 6 | 7 | ### Second Round - Design: 8 | + In-Depth questions on BSTs and graphs. 9 | + Real time Application use-case involving updation of news feed/facebook feed/twitter feed based on ranking of the incoming data stream of posts, comments, reactions such that posts are sorted by highest rank followed by post with lesser rank and so on - Do this in real time - Design an efficient feed management system. 10 | 11 | ### Third Round - Managerial: 12 | + Questions on your technical experience and projects you have done. 13 | + Challenges in the projects, how are scaling issues resolved, Team work, Milestones achieved etc. 14 | + Questions on Deployment process followed and tools used for deploying codebase - devops architecture, CI/CD, Docker, Kubernetes, Service mesh and containerization etc 15 | 16 | ### Fourth Round - HR round: 17 | + Questions are similar to questions from any other HR round. 18 | + what are you looking for? what are your career aspirations? 19 | + what are your interests and why are you interested in athenahealth? 20 | + Any other doubts and clarifications on the role, Planning connects with Hiring manager etc. 21 | -------------------------------------------------------------------------------- /Betterworks/README.md: -------------------------------------------------------------------------------- 1 | # Hiring process for Betterworks Software Engineer Role (Personal Experience): 2 | 3 | ## First round: 4 | + Discussion from Director of Engineering/Lead Engineer on your work experience, Job description, you expertise on skills required for the role, understand your skillset, projects that you have worked in and have been working on at the moment - critical challenges faced and how you have overcome them etc. 5 | 6 | ## Second round: 7 | + Technical screening on basic coding questions. 8 | + Basic questions on pandas data munging steps, write a simple algorithm (Given a pair of string and numbers ex: one 1, two 2, three 3, four 4, five 5 - print sequence like this - (n,1),(w,2),(r,3),(ou,4),(iv,5). 9 | + sorting techniques, python built-in data structures and questions on the same. 10 | + questions on python decorators. 11 | 12 | ## Third round: 13 | + Hands-on Assignment where you have to build a working prototype of an API (Assignment will be shared in the form of PDF). 14 | 15 | ## Fourth round: 16 | + Questions on pandas data analysis techniques groupby, aggregations, distributions, visualizing the bar charts, boxplots. 17 | + SQL - primary keys, foreign keys, composite keys, Indexes, star and snowflake schemas. 18 | + Write an algorithm that does the following, Given a array of integers and element x - find all the elements of array that are closer to given number x (Numbers having minimum difference with x)(questions on time complexity, scope for optimization,efficiency). 19 | + Questions on Github, process of deployment and development you follow in your regular projects at work with github. when would you use git squash, git merge, git rebase etc. 20 | + Questions on REST API, design techniques etc. 21 | -------------------------------------------------------------------------------- /Betterworks/print.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a dictionary of elements: 3 | mydict = {'one':1, 4 | 'two':2, 5 | 'three':3, 6 | 'four':4, 7 | 'five':5} 8 | print the sequence of elements in the following fashion: 9 | {'n':1,'w':2,'r':3,'ou':4,'iv':5} 10 | 11 | """ 12 | 13 | mydict = {'one':1, 14 | 'two':2, 15 | 'three':3, 16 | 'four':4, 17 | 'five':5} 18 | 19 | def doop(mydict): 20 | if len(mydict) == 0: 21 | return "no data" 22 | res = {} 23 | for k,v in mydict.items(): 24 | leng = len(k) 25 | if leng%2 != 0: 26 | res.update({k[(leng-1)//2]:v}) 27 | else: 28 | key = ''.join([k[(leng-1)//2],k[(leng+1)//2]]) 29 | res.update({key:v}) 30 | return res 31 | 32 | print (doop(mydict)) -------------------------------------------------------------------------------- /Bloomberg/moveAllZerosToEndOfArray.py: -------------------------------------------------------------------------------- 1 | def moveZerosToEnd(arr): 2 | arr_0 = [x for x in arr if x!=0] 3 | zeros = [0] * (len(arr)-len(arr_0)) 4 | ans = arr_0 + zeros 5 | return " ".join(str(u) for u in ans) 6 | 7 | if __name__ == '__main__': 8 | T = int(input()) 9 | for t in range(T): 10 | N = int(input()) 11 | arr = list(map(int,input().strip().split())) 12 | print (moveZerosToEnd(arr)) -------------------------------------------------------------------------------- /BrightMoney/Data_Analyst_Test.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/BrightMoney/Data_Analyst_Test.docx -------------------------------------------------------------------------------- /BrightMoney/Knapsack.py: -------------------------------------------------------------------------------- 1 | """ 2 | 0-1 Knapsack problem 3 | 4 | """ -------------------------------------------------------------------------------- /BrightMoney/LongestBalancedSubstring.py: -------------------------------------------------------------------------------- 1 | """ 2 | Longest balanced substring given a string containing only parenthesis (open and 3 | closed curly braces) 4 | 5 | Refer https://www.geeksforgeeks.org/length-of-the-longest-valid-substring/ 6 | along with the length, also print the start and end indices of this longest substring 7 | 8 | Refer below custom addition to the existing code 9 | 10 | """ 11 | 12 | 13 | def findMaxLen(string): 14 | n = len(string) 15 | 16 | # Create a stack and push -1 as initial index to it. 17 | stk = [] 18 | stk.append(-1) 19 | 20 | # Initialize result 21 | result = 0 22 | tracker = [] 23 | 24 | # Traverse all characters of given string 25 | for i in range(n): 26 | 27 | # If opening bracket, push index of it 28 | if string[i] == '{': 29 | stk.append(i) 30 | 31 | else: # If closing bracket, i.e., str[i] = '}' 32 | 33 | # Pop the previous opening bracket's index 34 | stk.pop() 35 | 36 | # Check if this length formed with base of 37 | # current valid substring is more than max 38 | # so far 39 | if len(stk) != 0: 40 | if result < i - stk[len(stk)-1]: 41 | result = i - stk[len(stk)-1] 42 | tracker.append((result,i)) 43 | 44 | # If stack is empty. push current index as 45 | # base for next valid substring (if any) 46 | else: 47 | stk.append(i) 48 | 49 | return result,tracker 50 | 51 | #string = "{{{}" 52 | #string = "}{}{}}" 53 | string = "{}{{}}}}}" 54 | result,tracker = findMaxLen(string) 55 | for t in tracker: 56 | if t[0] == result: 57 | end_index = t[1] 58 | 59 | # length of longest substring (balanced) 60 | print (result) 61 | 62 | # print (start and end locations of that substring) 63 | print (" ".join([str(end_index - result + 2),str(end_index + 1)])) -------------------------------------------------------------------------------- /BrightMoney/README.md: -------------------------------------------------------------------------------- 1 | # Coding questions on DoSelect Platform (Personal Experience) (Data Science roles - ML Engineering) (4 Coding questions are added here) 2 | + This process is different from Data analyst process. 3 | 4 | # Interview Process for Data Analyst position: 5 | ## First round - DoSelect Assessment for Data Analyst positions/Word Document on email: 6 | + There are different kinds of assessments being used by BrightMoney for Data analyst positions: 7 | - It can send you a word document (Refer word document above) consisting of questions & asking you to write sql queries for different scenarios in the document and also to replicate the same logic using pandas in python (use sqlite). 8 | - It can also send you DoSelect link where there are two questions, one question to be solved using pandas for simple data manipulation and other is you have to write a sql query (Given different tables by showing relationships between all tables like an ER diagram with indications of primary and foreign keys) 9 | 10 | ## Second round - Business Case study from the founder of Brightmoney.co: 11 | + Given a case study around credit cards and checking accounts with financial lingo, build your hypothesis and present a solution as to why you think your approach is accurate compared to other possible approaches? What are the different problems with your approach? What can be challenges with the data you are taking? etc (Deleted the case study ppt to avoid DMCA notices). 12 | -------------------------------------------------------------------------------- /BrightMoney/countDistinctValidPANNumbers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a paragraph of P words, find all valid PAN card numbers in that paragraph 3 | """ -------------------------------------------------------------------------------- /BrightMoney/printSpirally.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given an integer n, generate a square matrix from entries from 1 to n**2 in 3 | spiral pattern 4 | 5 | """ 6 | 7 | def generateMatrix(n): 8 | if n <= 0: 9 | return [] 10 | result = [[None for i in range(n)] for j in range(n)] 11 | xBeg,xEnd = 0,n-1 12 | yBeg,yEnd = 0,n-1 13 | current = 1 14 | while (True): 15 | for i in range(yBeg,yEnd+1): 16 | result[xBeg][i] = current 17 | current += 1 18 | xBeg += 1 19 | if (xBeg > xEnd): 20 | break 21 | for i in range(xBeg,xEnd+1): 22 | result[i][yEnd] = current 23 | current += 1 24 | yEnd -= 1 25 | if (yEnd < yBeg): 26 | break 27 | for i in range(yEnd,yBeg-1,-1): 28 | result[xEnd][i] = current 29 | current += 1 30 | xEnd -= 1 31 | if (xEnd < xBeg): 32 | break 33 | for i in range(xEnd,xBeg-1,-1): 34 | result[i][yBeg] = current 35 | current += 1 36 | yBeg += 1 37 | if (yBeg > yEnd): 38 | break 39 | return result 40 | 41 | rows = generateMatrix(9) 42 | for row in rows: 43 | print (" ".join(str(i) for i in row)) -------------------------------------------------------------------------------- /Busigence/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process - Personal (Data Engineer - Python/Pyspark/Scala-spark) - 2021: 2 | ### First round: 3 | + Take Home assignment on Spark coding. 4 | + The solutions added above are correct (Got selected to next round) 👍 🙂. 5 | -------------------------------------------------------------------------------- /Byndr/README.md: -------------------------------------------------------------------------------- 1 | # Interview Experience for Data Engineer (Big Data) - 2021: 2 | ### First Round: 3 | + What is Hive? 4 | + What is Hive metastore? 5 | + Hive external table vs managed table. 6 | + evalute Programming skills - one question on that. 7 | + mappers and reducers in Spark execution flow. 8 | + what are `groupByKey` and `reduceByKey` operations in Spark. 9 | + Write spark skeleton code for given scenario - reading a CSV and do some transformations on it - Code doesn't have to be exact but steps matter. 10 | + Given a requirement (find the second largest value of a column for every value of other column - Window functions in SQL), what are the steps to achieve it using only spark-sql without dataframes/RDDs API in spark? 11 | + Questions on SQL for window functions in spark (SQL query is preferred compared to Dataframes API). 12 | + Different storage formats in big data space? questions on that (`parquet`, `CSV`, `JSON`, `avro`, `delta` etc). 13 | + Questions on Hadoop ecosystem if any. 14 | -------------------------------------------------------------------------------- /CloudCover/README.md: -------------------------------------------------------------------------------- 1 | # Personal Experience for Data Engineer - 2021: 2 | ## First round: 3 | Live Programming round - Given 1.5 hrs of time, you need to solve a problem statement live on web based IDE. 4 | 5 | ## Second round: 6 | Techical Discussion on the projects done, Some interview questions on Spark,Hive,Hadoop: 7 | - About windows functions in spark, what they are used for in spark? 8 | - About UDFs in spark and how they are different from normal spark functions in performance. 9 | - Difference between external table and managed table in hive. 10 | - experience on moving large scale data between different sinks? cloud migrations? database migrations? 11 | - experience writing complex sql queries? 12 | - behaviorial questions. 13 | - current project and what are the responsibilities of your role specifically in your company. 14 | - some other questions on bigdata, which I don't remember right now 😁 15 | -------------------------------------------------------------------------------- /Facebook/ImplementSTRSTR.py: -------------------------------------------------------------------------------- 1 | { 2 | #Contributed by : Nagendra Jha 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__ == '__main__': 14 | t=int(input()) 15 | for cases in range(t): 16 | s,p =input().strip().split() 17 | print(strstr(s,p)) 18 | 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | ''' 22 | Your task is to return the index of the pattern 23 | present in the given string. 24 | 25 | Function Arguments: s (given text), p(given pattern) 26 | Return Type: Integer. 27 | 28 | ''' 29 | def strstr(s,p): 30 | #code here 31 | import re 32 | loc = re.search(p,s) 33 | if loc is not None: 34 | return (loc.start()) 35 | else: 36 | return -1 -------------------------------------------------------------------------------- /FactSet/convertArrayToWave.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | 6 | T=int(input()) 7 | 8 | while(T>0): 9 | 10 | 11 | N=int(input()) 12 | 13 | A=[int(x) for x in input().split()] 14 | convertToWave(A,N) 15 | for i in A: 16 | print(i,end=" ") 17 | 18 | 19 | print() 20 | 21 | 22 | T-=1 23 | if __name__=="__main__": 24 | main() 25 | } 26 | ''' This is a function problem.You only need to complete the function given below ''' 27 | #User function Template for python3 28 | #Complete this function 29 | def convertToWave(A,N): 30 | #Your code here 31 | temp=0 32 | for i in range(N-1): 33 | if i%2 == 0: 34 | if A[i] < A[i+1]: 35 | temp=A[i] 36 | A[i]=A[i+1] 37 | A[i+1]=temp 38 | else: 39 | continue 40 | else: 41 | if A[i] > A[i+1]: 42 | temp=A[i] 43 | A[i]=A[i+1] 44 | A[i+1]=temp 45 | else: 46 | continue -------------------------------------------------------------------------------- /Flipkart/addTwoNumbers_LinkedListRep.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(head): 36 | if head is None: 37 | print(' ') 38 | return 39 | curr_node = head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | if __name__ == '__main__': 45 | t=int(input()) 46 | for cases in range(t): 47 | n_a = int(input()) 48 | a = LinkedList() # create a new linked list 'a'. 49 | nodes_a = list(map(int, input().strip().split())) 50 | nodes_a = nodes_a[::-1] # reverse the input array 51 | for x in nodes_a: 52 | a.append(x) # add to the end of the list 53 | n_b =int(input()) 54 | b = LinkedList() # create a new linked list 'b'. 55 | nodes_b = list(map(int, input().strip().split())) 56 | nodes_b = nodes_b[::-1] # reverse the input array 57 | for x in nodes_b: 58 | b.append(x) # add to the end of the list 59 | result_head = addBoth(a.head,b.head) 60 | printList(result_head) 61 | } 62 | ''' This is a function problem.You only need to complete the function given below ''' 63 | #User function Template for python3 64 | ''' 65 | Function to add two numbers represented 66 | in the form of the linked list. 67 | 68 | Function Arguments: head_a and head_b (heads of both the linked lists) 69 | Return Type: head of the resultant linked list. 70 | 71 | __>IMP : numbers are represented in reverse in the linked list. 72 | Ex: 73 | 145 is represented as 5->4->1. 74 | 75 | resultant head is expected in the same format. 76 | 77 | # Node Class 78 | class Node: 79 | def __init__(self, data): # data -> value stored in node 80 | self.data = data 81 | self.next = None 82 | ''' 83 | def addBoth(head_a,head_b): 84 | #code here 85 | result = LinkedList() 86 | num1 = "" 87 | curr_node = head_a 88 | while curr_node != None: 89 | num1 += str(curr_node.data) 90 | curr_node = curr_node.next 91 | num1 = num1[::-1] 92 | num2 = "" 93 | curr_node = head_b 94 | while curr_node != None: 95 | num2 += str(curr_node.data) 96 | curr_node = curr_node.next 97 | num2 = num2[::-1] 98 | num = int(num1) + int(num2) 99 | num = str(num)[::-1] 100 | for i in num: 101 | result.append(i) 102 | return result.head -------------------------------------------------------------------------------- /Flipkart/countOfInversionsArray.py: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks Code - Copied# 2 | { 3 | #Initial Template for Python 3 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__=='__main__': 15 | t = int(input()) 16 | for tt in range(t): 17 | n = int(input()) 18 | a = list(map(int, input().strip().split())) 19 | print(Inversion_Count(a,n)) 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ''' 24 | Your task is to return total number of inversions 25 | present in the array. 26 | 27 | Function Arguments: array a and size n 28 | Return Type: Integer 29 | ''' 30 | def Inversion_Count(arr,n): 31 | if a == sorted(a): 32 | return 0 33 | temp_arr = [0]*n 34 | return mergesort(arr,temp_arr,0,n-1) 35 | 36 | def mergesort(arr,temp_arr,left,right): 37 | inv_count = 0 38 | if left < right: 39 | mid = (left + right)//2 40 | inv_count = mergesort(arr,temp_arr,left,mid) 41 | inv_count += mergesort(arr,temp_arr,mid+1,right) 42 | inv_count += merge(arr,temp_arr,left,mid,right) 43 | return inv_count 44 | 45 | def merge(arr,temp_arr,left, mid, right): 46 | # Merge the temp arrays back into arr[l..r] 47 | i = left # Initial index of first subarray 48 | j = mid+1 # Initial index of second subarray 49 | k = left # Initial index of merged subarray 50 | invcount = 0 51 | while i <= mid and j <= right: 52 | if arr[i] <= arr[j]: 53 | temp_arr[k] = arr[i] 54 | i += 1 55 | else: 56 | temp_arr[k] = arr[j] 57 | invcount += (mid - i + 1) 58 | j += 1 59 | k += 1 60 | # Copy the remaining elements of L[], if there 61 | # are any 62 | while i <= mid: 63 | temp_arr[k] = arr[i] 64 | i += 1 65 | k += 1 66 | # Copy the remaining elements of R[], if there 67 | # are any 68 | while j <= right: 69 | temp_arr[k] = arr[j] 70 | j += 1 71 | k += 1 72 | 73 | for lr in range(left, right + 1): 74 | arr[lr] = temp_arr[lr] 75 | return invcount 76 | -------------------------------------------------------------------------------- /Flipkart/parenthesisChecker.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | #Contributed by : Nagendra Jha 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__ == '__main__': 15 | test_cases = int(input()) 16 | for cases in range(test_cases) : 17 | #n = int(input()) 18 | #n,k = map(int,imput().strip().split()) 19 | #a = list(map(int,input().strip().split())) 20 | s = str(input()) 21 | if ispar(s): 22 | print("balanced") 23 | else: 24 | print("not balanced") 25 | } 26 | ''' This is a function problem.You only need to complete the function given below ''' 27 | #User function Template for python3 28 | ''' 29 | Function Arguments : 30 | @param : s (given string containing parenthesis) 31 | @return : boolean True or False 32 | ''' 33 | 34 | def isMatchingPair(c1,c2): 35 | if (c1=='(') & (c2==')'): 36 | return True 37 | elif (c1=='{') & (c2=='}'): 38 | return True 39 | elif (c1=='[') & (c2==']'): 40 | return True 41 | else: 42 | return False 43 | 44 | def ispar(s): 45 | # code here 46 | import queue 47 | stack = queue.LifoQueue() 48 | 49 | for i in range(len(s)): 50 | if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')): 51 | stack.put(s[i]) 52 | if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')): 53 | if stack.empty(): 54 | return False 55 | elif not isMatchingPair(stack.get(),s[i]): 56 | return False 57 | 58 | if stack.empty(): 59 | return True 60 | else: 61 | return False -------------------------------------------------------------------------------- /Fractal_Analytics/Arrays.md: -------------------------------------------------------------------------------- 1 | Given an array A of size N as an input, return the following: 2 | + for every element of array, find the sum of elements upto that element(inclusive): 3 | 4 | Examples: 5 | ``` 6 | A = [3,5,6,9,10], N = 5 7 | for 3, sum of elements upto 3 is 0 + 1 + 2 + 3 = 6. 8 | for 5, sum of elements upto 5 is 0 + 1 + 2 + 3 + 4 + 5 = 15. 9 | for 6, sum of elements upto 6 is 0 + 1 + 2 + 3 + 4 + 5 + 6 = 21. 10 | for 9, sum of elements upto 9 is 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45. 11 | for 10, sum of elements upto 10 is 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55. 12 | -------------------------------------------------------------------------------- /Fractal_Analytics/Comparator.md: -------------------------------------------------------------------------------- 1 | 1. Write a comparator class with overloaded methods that perform below operations 2 | - a. `compare(int a,int b)` that takes two integers `a` and `b` and returns `True` if `a == b` else `False`. 3 | - b. `compare(string a,string b)` that takes two strings `a` and `b` as parameters and returns `True` if `a == b` else `False`. 4 | - c. `compare(int a[],int b[])` that takes two 1-Dimensional Arrays `a` and `b` as parameters and checks the following 5 | conditions 6 | - if length of `a` is equal to `b`. 7 | - for every index `i` of a, `a[i] == b[i]`. 8 | returns `True` only if above two conditions hold true otherwise returns `False`. 9 | -------------------------------------------------------------------------------- /Fractal_Analytics/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process for Analytics Consultant - 2019: 2 | ### First round: 3 | + Hackerrank Test (Python + SQL) or (R + SQL) test (4 python/R + 4 sql questions)(python questions are normal coding questions). 4 | ### Second round: 5 | + Questions on projects from CV/Machine learning algorithms for time series,classification usecases and case study(How would you approach the problem of maximizing a variable from model results)? 6 | 7 | # Interview Process for Analytics Consultant - 2020: 8 | ### First round: 9 | + DoSelect Test (Python + SQL) or (R + SQL) test (4 python/R + 4 sql questions) (Python questions are not coding questions but 10 | questions on pandas and numpy coding). 11 | 12 | # Interview Process for Senior Big Data Engineer - 2021: 13 | ### First round: 14 | + DoSelect Test (Coding Test). 15 | 16 | ### Second round: 17 | + Technical questions on Hive, Spark (Accumulator and Broadcast variables usecases), real world examples, and testing coding skills - Data structures and algorithms (Time complexity and Space complexity analysis). 18 | + Focus on Spark application performance tuning techniques. 19 | + In-depth SQL questions - solve using either SQL query or dataframes/datasets API in spark. 20 | 21 | ### Third round: 22 | + Interview with the Director/VP on background, questions to check if you are the right fit for the role, etc. 23 | 24 | ### Fourth round: 25 | + HR round - process improvements, challenges faced in the past etc. 26 | -------------------------------------------------------------------------------- /Fractal_Analytics/countChampNumbers.py: -------------------------------------------------------------------------------- 1 | """ 2 | find the count of champ numbers in given range [X,Y] (inclusive) 3 | Champ numbers are numbers which have all the digits as unique 4 | and no digit should be greater than 5 5 | 6 | """ 7 | 8 | def countChampNumbers(X,Y): 9 | count = 0 10 | for i in range(X,Y+1): 11 | if len(str(i)) == 1 and i <= 5: 12 | print (i) 13 | count += 1 14 | else: 15 | if len(set(str(i))) == len(str(i)): 16 | if not (('6' in str(i)) or ('7' in str(i)) or 17 | ('8' in str(i)) or ('9' in str(i))): 18 | print(i) 19 | count += 1 20 | return count 21 | 22 | if __name__ == '__main__': 23 | T = int(input()) 24 | for tc in range(T): 25 | X,Y = list(map(int, input().strip().split())) 26 | print (countChampNumbers(X,Y)) -------------------------------------------------------------------------------- /Fractal_Analytics/countOfAnagrams.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a text and a word, find the count of occurrences of anagrams 3 | of word in given text 4 | 5 | """ 6 | 7 | def countAnagrams(text,word): 8 | count=0 9 | b = text 10 | a = word 11 | for i in range(len(b)-len(a)+1): 12 | if(sorted(a)==sorted(b[i:i+len(a)])): 13 | count=count+1 14 | return count 15 | 16 | 17 | if __name__ == '__main__': 18 | text = str(input()) 19 | word = str(input()) 20 | print (countAnagrams(text, word)) -------------------------------------------------------------------------------- /Fractal_Analytics/numberOfGroups.py: -------------------------------------------------------------------------------- 1 | """ 2 | A pole of the magnet is represented as "01" or "10" 3 | 1 = North pole and 0 = South pole 4 | we know the like poles of magnet repel each other but unlike poles 5 | attract. 6 | Suppose a magnet has pole "10" and adjacent magnet also has "10" 7 | they attract 8 | if a magnet "01" is located adjacent to magnet "10" they repel. 9 | 10 | Given a list of poles of different magnets, find the number of the 11 | separate groups that magnets form into 12 | 13 | example: 14 | number of magnets = 3 15 | 01 16 | 01 17 | 10 18 | 19 | number of groups = 2 because first 2 magnets attract each other 20 | so will be in the same group where as the third one repels 21 | second one so will be in different group 22 | """ 23 | 24 | 25 | def numGroups(poles): 26 | groups = [poles[0]] 27 | for i in range(1,len(poles)): 28 | if poles[i][0] == groups[-1][0]: 29 | groups.append(poles[i]) 30 | else: 31 | groups.append(' ') 32 | groups.append(poles[i]) 33 | concat_groups = ''.join(groups) 34 | print (concat_groups) 35 | return len(concat_groups.split(' ')) 36 | 37 | if __name__ == '__main__': 38 | n = int(input()) 39 | poles = [] 40 | for tc in range(n): 41 | pole = input() 42 | poles.append(pole) 43 | print (numGroups(poles)) -------------------------------------------------------------------------------- /Fractal_Analytics/sorting_words.md: -------------------------------------------------------------------------------- 1 | Given a sentence, sort the words of a sentence according to the their individual lengths. If one or more words have same length 2 | then sort the words by first character of the word. 3 | 4 | ``` 5 | Example: 6 | Input: The quick brown fox jumps over the lazy dog 7 | Output: dog fox the The lazy over brown jumps quick 8 | 9 | ``` 10 | + This problem can be extended to sorting the words by second letter in case of collision with first letter and continue 11 | till the end of word and stop when collision is resolved. 12 | -------------------------------------------------------------------------------- /Fractal_Analytics/substrings.md: -------------------------------------------------------------------------------- 1 | 2 | 2. Get the number of distinct substrings possible for a given string, you can use the below operations: 3 | 4 | - a. Remove 0 or more characters from left side of the string. 5 | - b. Remove 0 or more characters from right side of string. 6 | - c. Remove 0 or more characters from both left and right side of string. 7 | 8 | Examples: 9 | ``` 10 | Input : str = “ababa” 11 | Output : 10 12 | Total number of distinct substring are 10, which are, 13 | "", "a", "b", "ab", "ba", "aba", "bab", "abab", "baba" 14 | and "ababa" 15 | ``` 16 | ``` 17 | Input : abcd 18 | Output : abcd abc ab a bcd bc b cd c d 19 | All Elements are Distinct 20 | ``` 21 | ``` 22 | Input : aaa 23 | Output : aaa aa a aa a a 24 | All elements are not Distinct 25 | ``` 26 | -------------------------------------------------------------------------------- /Fre8wise/README.md: -------------------------------------------------------------------------------- 1 | # Process for Software engineer role: 2 | ## First round: 3 | 1. First round is with founder of the company - This is an exploratory call about company's profile, your background, projects and why you are looking for a change, CTC details - Even a demo of what company is doing is included on Zoom call 4 | 5 | ## Second round: 6 | 1. Technical interview with one of the technical leads. 7 | 2. Questions from the CV, work experience, challenges in projects you have undertaken. 8 | 3. Design a queueing system that serves multiple agents looking for differnet datasets being produced from different producers/systems. 9 | 4. Memory management in Data engineering pipelines. 10 | 5. Questions on lambda architecture. 11 | 6. Questions on nitty-gritty details of how you executed projects in production. 12 | 7. Focus on system design and understanding. 13 | -------------------------------------------------------------------------------- /Fre8wise/manipulate_string.py: -------------------------------------------------------------------------------- 1 | """ 2 | Solve the following algorithm problem: 3 | Given a string, develop a solution that removes only 1's 4 | in the beginning 5 | 6 | Examples: 7 | 1198fgh098nm -> 98fgh098nm 8 | a1198fgh098nm -> a1198fgh098nm 9 | a1198fgh098nm11 -> a1198fgh098nm11 10 | """ 11 | 12 | s = "1198fgh098nm" 13 | 14 | 15 | def changeString(s): 16 | try: 17 | while (s.index("1") == 0): 18 | slist = list(s) 19 | temp = slist.pop(0) 20 | s = "".join(slist) 21 | except: 22 | pass 23 | return s 24 | 25 | if __name__ == '__main__': 26 | s = input() 27 | print (changeString(s)) -------------------------------------------------------------------------------- /Goldman-Sachs/convertArrayToWave.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | 6 | T=int(input()) 7 | 8 | while(T>0): 9 | 10 | 11 | N=int(input()) 12 | 13 | A=[int(x) for x in input().split()] 14 | convertToWave(A,N) 15 | for i in A: 16 | print(i,end=" ") 17 | 18 | 19 | print() 20 | 21 | 22 | T-=1 23 | if __name__=="__main__": 24 | main() 25 | } 26 | ''' This is a function problem.You only need to complete the function given below ''' 27 | #User function Template for python3 28 | #Complete this function 29 | def convertToWave(A,N): 30 | #Your code here 31 | temp=0 32 | for i in range(N-1): 33 | if i%2 == 0: 34 | if A[i] < A[i+1]: 35 | temp=A[i] 36 | A[i]=A[i+1] 37 | A[i+1]=temp 38 | else: 39 | continue 40 | else: 41 | if A[i] > A[i+1]: 42 | temp=A[i] 43 | A[i]=A[i+1] 44 | A[i+1]=temp 45 | else: 46 | continue -------------------------------------------------------------------------------- /Goldman-Sachs/numberOfSquares_in_NbyN_CheesBoard.py: -------------------------------------------------------------------------------- 1 | def num_of_squares(n): 2 | if n == 1: 3 | return (1) 4 | else: 5 | nSquares = 0 6 | for I in range(1,n+1): 7 | nSquares = nSquares + (I*I) 8 | return (nSquares) 9 | 10 | 11 | if __name__ == '__main__': 12 | T = int(input()) 13 | for tcase in range(T): 14 | n = int(input()) 15 | print (num_of_squares(n)) -------------------------------------------------------------------------------- /Goldman-Sachs/printNumbersContain123.py: -------------------------------------------------------------------------------- 1 | def contains123(arr): 2 | c = {'1','2','3'} 3 | tracker = [] 4 | arr = sorted(arr) 5 | for i in arr: 6 | a = set(str(i)) 7 | if a.issubset(c): 8 | print (i,end=" ") 9 | tracker.append(1) 10 | else: 11 | tracker.append(0) 12 | if len(set(tracker))==1 and 0 in tracker: 13 | print (-1,end="") 14 | 15 | if __name__ == '__main__': 16 | t = int(input()) 17 | for tcase in range(t): 18 | n = int(input()) 19 | arr = list(map(int,input().strip().split())) 20 | contains123(arr) 21 | print ('\n',end="") -------------------------------------------------------------------------------- /Goldman-Sachs/repeatingCharacter_LeftmostOccurrence.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__=='__main__': 14 | t = int(input()) 15 | for i in range(t): 16 | s=str(input()) 17 | index=repeatingCharacter(s) 18 | if(index==-1): 19 | print(-1) 20 | else: 21 | print(s[index]) 22 | 23 | } 24 | ''' This is a function problem.You only need to complete the function given below ''' 25 | #User function Template for python3 26 | ''' 27 | Your task is to return the lefmost index of the repeating 28 | character whose first appereance is left most or return 29 | -1 if all characters are distinct. 30 | 31 | Function Arguments: s (given string) 32 | Return Type: integer 33 | ''' 34 | def repeatingCharacter(s): 35 | #code here 36 | import collections 37 | freqs = collections.Counter(s) 38 | if len(set(freqs.values())) == 1 and 1 in set(freqs.values()): 39 | return -1 40 | else: 41 | inds = [] 42 | for k,v in freqs.items(): 43 | if v > 1: 44 | inds.append(s.index(k)) 45 | return min(inds) -------------------------------------------------------------------------------- /Google/First_Recurring_Character_In_String.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | input_string = input() 3 | 4 | def firstRecurringChar(input_string): 5 | recurring_chars= [] 6 | count_dict = Counter(input_string) 7 | for x, y in count_dict.items(): 8 | if y > 1: 9 | recurring_chars.append(x) 10 | if recurring_chars: 11 | return recurring_chars[0] 12 | else: 13 | return (-1) 14 | 15 | if __name__ == '__main__': 16 | print (firstRecurringChar(input_string)) -------------------------------------------------------------------------------- /Google/allocateMinimumPages.py: -------------------------------------------------------------------------------- 1 | import math 2 | def isValid(arr,n,k,mi): 3 | std = 1 4 | curr = 0 5 | for i in range(n): 6 | if curr + arr[i] > mi: 7 | curr = arr[i] 8 | std += 1 9 | if std > k: 10 | return False 11 | else: 12 | curr += arr[i] 13 | return True 14 | 15 | def allocMinPages(arr,n,k): 16 | if k > n: 17 | return -1 18 | s,totalpage = 0,0 19 | for i in range(n): 20 | totalpage += arr[i] 21 | s = max(s,arr[i]) 22 | e = totalpage 23 | finalAns = s 24 | while s <= e: 25 | mid = math.floor((s+e)/2) 26 | if isValid(arr,n,k,mid): 27 | finalAns = mid 28 | e = mid - 1 29 | else: 30 | s = mid + 1 31 | return finalAns 32 | 33 | if __name__ == '__main__': 34 | T = int(input()) 35 | for tcase in range(T): 36 | N = int(input()) 37 | arr = list(map(int,input().strip().split())) 38 | M = int(input()) 39 | print (allocMinPages(arr,N,M)) -------------------------------------------------------------------------------- /Google/checkPairsWithGivenSum.py: -------------------------------------------------------------------------------- 1 | """ 2 | This problem was recently asked by Google. 3 | 4 | Given a list of numbers and a number k, return whether any two numbers from the 5 | list add up to k. 6 | 7 | For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. 8 | """ 9 | 10 | 11 | def isPairWithGivenSum(arr,n,x): 12 | left,right = 0,n-1 13 | arr = sorted(arr) 14 | while left < right: 15 | if ((arr[left] + arr[right]) < x): 16 | left += 1 17 | elif (arr[left] + arr[right] == x): 18 | return True 19 | elif (arr[left] + arr[right] > x): 20 | right -= 1 21 | return False 22 | 23 | if __name__ == '__main__': 24 | T = int(input()) 25 | for tcs in range(T): 26 | arr = list(map(int,input().strip().split())) 27 | n = len(arr) 28 | x = int(input()) 29 | print (isPairWithGivenSum(arr,n,x)) -------------------------------------------------------------------------------- /Google/maxIndexDiffOfArray.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | print(maxIndexDiff(arr,n)) 12 | 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | #Complete this function 21 | def maxIndexDiff(arr, n): 22 | ##Your code here 23 | maxxDiff = 0 24 | for i in range(n): 25 | for j in range(i+1,n): 26 | if arr[i]<=arr[j]: 27 | if maxxDiff < j - i: 28 | maxxDiff = j - i 29 | return maxxDiff -------------------------------------------------------------------------------- /Grofers/QuickSort.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | if __name__ == "__main__": 4 | t=int(input()) 5 | for i in range(t): 6 | n=int(input()) 7 | arr=list(map(int,input().split())) 8 | quickSort(arr,0,n-1) 9 | for i in range(n): 10 | print(arr[i],end=" ") 11 | print() 12 | 13 | } 14 | ''' This is a function problem.You only need to complete the function given below ''' 15 | #User function Template for python3 16 | def quickSort(arr,low,high): 17 | if low < high: 18 | 19 | # pi is partitioning index, arr[p] is now 20 | # at right place 21 | pi = partition(arr,low,high) 22 | 23 | # Separately sort elements before 24 | # partition and after partition 25 | quickSort(arr, low, pi-1) 26 | quickSort(arr, pi+1, high) 27 | 28 | def partition(arr,low,high): 29 | #add code here 30 | tmp = 0 31 | pivot = arr[high] 32 | i = low - 1 33 | for j in range(low,high): 34 | if arr[j] <= pivot: 35 | i += 1 36 | tmp = arr[i] 37 | arr[i] = arr[j] 38 | arr[j] = tmp 39 | tmp = arr[i+1] 40 | arr[i+1] = arr[high] 41 | arr[high] = tmp 42 | return i+1 -------------------------------------------------------------------------------- /Guardant-Health/README.md: -------------------------------------------------------------------------------- 1 | # Hackerrank Test (Personal Experience) 2 | -------------------------------------------------------------------------------- /Guardant-Health/fallen_leaves.py: -------------------------------------------------------------------------------- 1 | """ 2 | Coding Test - Hackerrank 3 | 4 | Given an array that has number of leaves on N trees (size of array = N)(arr[i] 5 | represents number of leaves for ith tree), 6 | percentage, array of days (can be in any order), starting and ending arrays 7 | 8 | Scenario: 9 | every day from each tree, given percentage of leaves will be fallen. 10 | 11 | Task: 12 | There are q queries,each query has day[q].starting[q] and ending[q] 13 | find out for each query how many leaves are fallen in total from 14 | all the trees with given start and end indices. 15 | 16 | Example: 17 | arr = [10,20,30,20,10] 18 | percentage = 30 19 | days = [1,1,2] 20 | starting = [2,1,1] 21 | ending = [4,3,4] 22 | 23 | after first day number of fallen leaves in the given range of starting[0] 24 | and ending[0] is 6 + 9 + 6 = 21 (required answer) 25 | Remaining leaves after first day = [7,14,21,14,7] 26 | 27 | In this way answer all the queries 28 | 29 | """ -------------------------------------------------------------------------------- /Guardant-Health/maintainMinimumStartingNumber.py: -------------------------------------------------------------------------------- 1 | """ 2 | Coding Test - Hackerrank 3 | 4 | what is the minimum starting number to maintain such that the running sum will 5 | always be atleast 1 6 | 7 | Example: 8 | arr = [3,-6,5,-2,1] 9 | 4 is the mininum number we need to start with 10 | Let's check: 11 | 4 + 3 = 7 12 | 7 + (-6) = 1 13 | 1 + 5 = 6 14 | 6 + (-2) = 4 15 | 4 + 1 = 5 16 | so it's 4. 17 | 18 | arr = [-4,3,-2,1] 19 | 5 is the minimum number we need to start with 20 | Let's check: 21 | 5 + (-4) = 1 22 | 1 + 3 = 4 23 | 4 + (-2) = 2 24 | 2 + 1 3 25 | so it's 5 26 | """ 27 | 28 | def minStartNumber(arr): 29 | bounds = [] 30 | total = 1 31 | for el in arr: 32 | total += (-1 * el) 33 | bounds.append(total) 34 | return max(bounds) 35 | 36 | 37 | if __name__ == '__main__': 38 | arr1 = [3,-6,5,-2,1] 39 | print (minStartNumber(arr1)) 40 | 41 | arr2 = [-4,3,-2,1] 42 | print (minStartNumber(arr2)) -------------------------------------------------------------------------------- /HighRadius-Technologies/README.md: -------------------------------------------------------------------------------- 1 | ## Interview questions (Personal Experience): 2 | 3 | #### 1. Confusion matrix for any classification algorithm is showed and what are precision and recall values from the matrix? 4 | 5 | + **What is precision**: `Number of True Positives / (Total number of Total Positives and False Positives)` 6 | + **What is Recall** : `Number of True Positives / (Total Number of Total Positives and False Negatives)` 7 | 8 | #### 2. How do you deal with overfitting in your machine learning model? 9 | 10 | + Regularization - (LASSO or Ridge Regression) (L1 and L2 regularization). 11 | + K-Fold cross validation with variable K. 12 | + Resampling of Train and Test splits of a datasets, sometimes involve out-of-time validation dataset. 13 | + Dimensionality Reduction in case of many features in a dataset. 14 | + Ensemble Learning. 15 | 16 | #### 3. How do you explain p-value to a layman? - Hypothesis testing. 17 | 18 | + p-value is metric by which we decide statistically significant variables. 19 | + It's a measure of how extreme an observed value is under the assumed null hypothesis: the smaller it is, the more extreme the 20 | observation. We can define p-value as the smallest significance level at which the null hypothesis would be rejected. 21 | + As the p-value gets smaller, we start wondering if the null hypothesis really is true and well maybe we should change our minds 22 | (and reject the null hypothesis). 23 | 24 | #### 4. How do you deal with concurrent predictions from decision Trees in ensemble algorithms like random forest? 25 | + Do some google research on this, there are multiple techniques to deal with this. 26 | -------------------------------------------------------------------------------- /Hike/QuickSort.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | if __name__ == "__main__": 4 | t=int(input()) 5 | for i in range(t): 6 | n=int(input()) 7 | arr=list(map(int,input().split())) 8 | quickSort(arr,0,n-1) 9 | for i in range(n): 10 | print(arr[i],end=" ") 11 | print() 12 | 13 | } 14 | ''' This is a function problem.You only need to complete the function given below ''' 15 | #User function Template for python3 16 | def quickSort(arr,low,high): 17 | if low < high: 18 | 19 | # pi is partitioning index, arr[p] is now 20 | # at right place 21 | pi = partition(arr,low,high) 22 | 23 | # Separately sort elements before 24 | # partition and after partition 25 | quickSort(arr, low, pi-1) 26 | quickSort(arr, pi+1, high) 27 | 28 | def partition(arr,low,high): 29 | #add code here 30 | tmp = 0 31 | pivot = arr[high] 32 | i = low - 1 33 | for j in range(low,high): 34 | if arr[j] <= pivot: 35 | i += 1 36 | tmp = arr[i] 37 | arr[i] = arr[j] 38 | arr[j] = tmp 39 | tmp = arr[i+1] 40 | arr[i+1] = arr[high] 41 | arr[high] = tmp 42 | return i+1 -------------------------------------------------------------------------------- /IQLECT/README.md: -------------------------------------------------------------------------------- 1 | # Asked to solve these questions in-person (In office) (No platform) 2 | -------------------------------------------------------------------------------- /InMobi/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process for Big Data Engineer 2020 (Personal): 2 | 1. First round of interview with onshore engineering manager from U.S.A. 3 | 2. Questions about your work experience on distributed systems, spark and data engineering pipelines. 4 | 3. what is it that you do as a part of your daily routine at work? 5 | 4. Tell me your understanding about hadoop? 6 | 5. What kind of challenges did you face in your projects? and How did you resolve them? 7 | 6. How do you handle memory leaks/failure of jobs due to memory errors? 8 | 7. Explain your understanding of hive internal table vs external table? 9 | 8. How did you optimize complex queries in hive? - partitions, buckets etc 10 | 9. How do you handle spark applications that are taking too long (certain task is leading to memory leaks)? 11 | -------------------------------------------------------------------------------- /Infrrd/problem01/maximumRowsWithAll1s.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | def maximumRows(binary_matrix,K): 4 | N = len(binary_matrix) 5 | M = len(binary_matrix[0]) 6 | numOf1s = [collections.Counter(x)[1] for x in binary_matrix] 7 | #Number of flips <= K 8 | maximum1s = max(numOf1s) 9 | #numOfRows_Maximum1s = collections.Counter(numOf1s)[maximum1s] 10 | total = [] 11 | for i in range(len(binary_matrix)): 12 | xyPairs1 = [] 13 | for j in range(M): 14 | if binary_matrix[i][j] == 1: 15 | xyPairs1.append(j) 16 | total.append(xyPairs1) 17 | maximum1sRows = [k for k,v in enumerate(numOf1s) if v == maximum1s] 18 | #maxmimize first Row 19 | finalCountList = [] 20 | for e in maximum1sRows: 21 | row = set(total[e]) 22 | UniversalSet = set(range(M)) 23 | needInc = UniversalSet-row 24 | checkList = sorted(list(set(range(N)) - {e})) 25 | a = checkList[0] 26 | b = checkList[len(checkList)-1] 27 | countList = [] 28 | for u in total[a:b+1]: 29 | count = 0 30 | if needInc & set(u): 31 | count += len(needInc & set(u)) 32 | countList.append(count) 33 | finalCountList.append(countList) 34 | return (len(finalCountList)//K) 35 | 36 | 37 | if __name__ == '__main__': 38 | N,M,K = list(map(int,input().strip().split())) 39 | binary_matrix = [] 40 | for I in range(N): 41 | row = list(map(int,input().strip().split())) 42 | binary_matrix.append(row) 43 | print (maximumRows(binary_matrix,K)) -------------------------------------------------------------------------------- /Infrrd/problem01/problem01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/Infrrd/problem01/problem01.png -------------------------------------------------------------------------------- /Infrrd/problem02/countMe.py: -------------------------------------------------------------------------------- 1 | def countMe(arrA,arrL,arrR,arrX): 2 | resultCount = [] 3 | for b in range(len(arrX)): 4 | targetX = arrX[b] 5 | p = arrL[b] 6 | q = arrR[b] 7 | resultCount.append(countOfNums(arrA[p-1:q],targetX)) 8 | return (" ".join(str(i) for i in resultCount)) 9 | 10 | def countOfNums(array,target): 11 | C = 0 12 | for x in array: 13 | if target%x == 0: 14 | C += 1 15 | return (C) 16 | 17 | if __name__ == '__main__': 18 | sizeOfA = int(input()) 19 | arrA = list(map(int,input().strip().split())) 20 | numQ = int(input()) 21 | arrL = list(map(int,input().strip().split())) 22 | arrR = list(map(int,input().strip().split())) 23 | arrX = list(map(int,input().strip().split())) 24 | print (countMe(arrA,arrL,arrR,arrX)) 25 | -------------------------------------------------------------------------------- /Infrrd/problem02/problem02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absognety/Interview-Process-Coding-Questions/f3c0491762f6e18d7d08de8dc51885176f7035ca/Infrrd/problem02/problem02.png -------------------------------------------------------------------------------- /Instabase/Add2BinaryStrings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Add two binary strings and get the resultant 3 | Hint: 4 | Try it without converting individual entities into numerical equivalents 5 | 6 | Solution: 7 | Refer: https://www.geeksforgeeks.org/program-to-add-two-binary-strings/ 8 | """ -------------------------------------------------------------------------------- /Instabase/README.md: -------------------------------------------------------------------------------- 1 | # Coding questions on Enthire (Personal Experience) 2 | -------------------------------------------------------------------------------- /Instabase/checkPairsWithGivenSum.py: -------------------------------------------------------------------------------- 1 | """ 2 | Daily Coding Problem #1 3 | This problem was recently asked by Google. 4 | 5 | Given a list of numbers and a number k, return whether any two numbers from the 6 | list add up to k. 7 | 8 | For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. 9 | """ 10 | 11 | 12 | def isPairWithGivenSum(arr,n,x): 13 | left,right = 0,n-1 14 | arr = sorted(arr) 15 | while left < right: 16 | if ((arr[left] + arr[right]) < x): 17 | left += 1 18 | elif (arr[left] + arr[right] == x): 19 | return True 20 | elif (arr[left] + arr[right] > x): 21 | right -= 1 22 | return False 23 | 24 | if __name__ == '__main__': 25 | T = int(input()) 26 | for tcs in range(T): 27 | arr = list(map(int,input().strip().split())) 28 | n = len(arr) 29 | x = int(input()) 30 | print (isPairWithGivenSum(arr,n,x)) -------------------------------------------------------------------------------- /Intuit/BuySellStock.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | stockBuySell(arr,n) 12 | print() 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | #Complete this function 21 | def stockBuySell(A,n): 22 | if A == sorted(A): 23 | print ("(" + str(0) + " " + str(n-1) + ")",end=" ") 24 | elif A == sorted(A,reverse=True): 25 | print ("No Profit",end = " ") 26 | else: 27 | local_min = [] 28 | local_max = [] 29 | for i,v in enumerate(A): 30 | if i == 0: 31 | if v < A[i+1]: 32 | local_min.append(i) 33 | elif i == n-1: 34 | if v > A[i-1]: 35 | local_max.append(i) 36 | else: 37 | if A[i-1] <= v and v >= A[i+1]: 38 | local_max.append(i) 39 | if A[i-1] >= v and v <= A[i+1]: 40 | local_min.append(i) 41 | if len(local_max) == len(local_min): 42 | for i in range(len(local_max)): 43 | x = " ".join([str(local_min[i]),str(local_max[i])]) 44 | print ("("+x+")",end=" ") 45 | else: 46 | x = " ".join([str(max(local_min)),str(max(local_max))]) 47 | print ("("+x+")",end = " ") -------------------------------------------------------------------------------- /Intuit/binaryArraySort.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | N=int(input()) 8 | A=list(map(int,input().split())) 9 | 10 | binSort(A,N) 11 | 12 | for i in A: 13 | print(i,end=" ") 14 | print() 15 | 16 | T-=1 17 | if __name__ == "__main__": 18 | main() 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | #User function Template for python3 22 | ##Complete this function 23 | def binSort(arr, n): 24 | #Your code here 25 | 26 | 27 | ''' 28 | No need to print the array 29 | ''' 30 | c0 = arr.count(0) 31 | c1 = arr.count(1) 32 | for i in range(c0): 33 | arr[i] = 0 34 | for i in range(c0,c0+c1): 35 | arr[i] = 1 -------------------------------------------------------------------------------- /Kritikal-Solutions/Delete_Without_Head_Pointer.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | def getNode(self,value): # return node with given value, if not present return None 35 | curr_node=self.head 36 | while(curr_node.next and curr_node.data != value): 37 | curr_node=curr_node.next 38 | if(curr_node.data==value): 39 | return curr_node 40 | else: 41 | return None 42 | # prints the elements of linked list starting with head 43 | def printList(self): 44 | if self.head is None: 45 | print(' ') 46 | return 47 | curr_node = self.head 48 | while curr_node: 49 | print(curr_node.data,end=" ") 50 | curr_node=curr_node.next 51 | print(' ') 52 | if __name__ == '__main__': 53 | t=int(input()) 54 | for cases in range(t): 55 | n = int(input()) 56 | a = LinkedList() # create a new linked list 'a'. 57 | nodes = list(map(int, input().strip().split())) 58 | for x in nodes: 59 | a.append(x) 60 | del_elem = int(input()) 61 | to_delete=a.getNode(del_elem) 62 | deleteNode(to_delete) 63 | a.printList() 64 | } 65 | ''' This is a function problem.You only need to complete the function given below ''' 66 | #User function Template for python3 67 | ''' 68 | Your task is to delete the given node from 69 | the linked list, without using head pointer. 70 | 71 | Function Arguments: node (given node to be deleted) 72 | Return Type: None, just delete the given node from the linked list. 73 | { 74 | # Node Class 75 | class Node: 76 | def __init__(self, data): # data -> value stored in node 77 | self.data = data 78 | self.next = None 79 | } 80 | Contributed By: Nagendra Jha 81 | ''' 82 | def deleteNode(curr_node): 83 | #code here 84 | prev = None 85 | curr = a.head 86 | while curr != None and curr_node != None: 87 | if curr.data == curr_node.data: 88 | if prev: 89 | prev.next = curr.next 90 | else: 91 | a.head = curr.next 92 | return 93 | prev = curr 94 | curr = curr.next -------------------------------------------------------------------------------- /LeadSquared/README.md: -------------------------------------------------------------------------------- 1 | # Coding Questions on mettl platform (Personal Experience) 2 | -------------------------------------------------------------------------------- /LeadSquared/UniqueWaysToClimbStaircase.py: -------------------------------------------------------------------------------- 1 | """ 2 | This question is asked in Interview 3 | 4 | There are n stairs, a person standing at the bottom wants to reach the 5 | top. The person can climb either 1 stair or 2 stairs at a time. Count 6 | the number of ways, the person can reach the top. 7 | 8 | Example: 9 | number of stairs = 5 10 | steps allowed = 1 or 2 11 | """ 12 | 13 | def countWays(n,m): 14 | """ 15 | Solution to above problem: 16 | Pros: 17 | It will consider all the possible steps from 1 to given m. 18 | Cons: 19 | No control by external user (if user wants to give only certain step values 20 | say in the form of an array). 21 | """ 22 | res = [None] * (n+1) 23 | temp = 0 24 | res[0] = 1 25 | for i in range(1,n+1): 26 | s = i - m - 1 27 | e = i - 1 28 | if s >= 0: 29 | temp -= res[s] 30 | temp += res[e] 31 | res[i] = temp 32 | print (res) 33 | return res[n] 34 | 35 | if __name__ == '__main__': 36 | n,m = 5,2 37 | print (countWays(n,m)) 38 | n,m = 5,3 39 | print (countWays(5,3)) 40 | 41 | 42 | def countWays1(n,args): 43 | """ 44 | Solution that mitigates the cons of above solution 45 | Give allowed step values in the form of an array (here it is args) 46 | """ 47 | m = len(args) 48 | count = [0 for i in range(n + 1)] 49 | 50 | # base case 51 | count[0] = 1 52 | 53 | # Count ways for all values up 54 | # to 'N' and store the result 55 | for i in range(1, n + 1): 56 | for j in range(m): 57 | 58 | # if i >= arr[j] then 59 | # accumulate count for value 'i' as 60 | # ways to form value 'i-arr[j]' 61 | if (i >= args[j]): 62 | count[i] += count[i - args[j]] 63 | 64 | # required number of ways 65 | return count[n] 66 | 67 | if __name__ == '__main__': 68 | print (countWays1(5,[2,3])) 69 | print (countWays1(5,[1,3,4])) 70 | print (countWays1(4,[1,3,4])) 71 | print (countWays1(10,[1,3,4])) 72 | print (countWays1(6,[3,2])) 73 | print (countWays1(5,[1,2,3])) 74 | print (countWays1(4,[1])) 75 | print (countWays1(4,[2])) 76 | print (countWays1(6,[3])) -------------------------------------------------------------------------------- /LeadSquared/maximumSumLikeTimeCoefficients.py: -------------------------------------------------------------------------------- 1 | """ 2 | Coding Test - Round 1 3 | 4 | Given an array of N integers (negative integers allowed) which say likings of 5 | N foods by a customer 6 | 7 | Time taken to prepare a food arr[i] is i 8 | 9 | like-time co-efficient of food is defined as i*arr[i]. Sum of like-time 10 | co-efficients can be obtained by doing the add up of i*arr[i] 11 | 12 | Find the maximum sum of like-time co-efficients that can be achieved from 13 | a given array. 14 | 15 | Hint: Consider all combinations of likings from a given array. 16 | 17 | Here is the idea: 18 | 19 | """ 20 | 21 | import itertools 22 | 23 | def maxSumLikeTimeCoeff(arr,N): 24 | all_sums = [] 25 | for r in range(1,N+1): 26 | combinations = set(itertools.combinations(arr,r)) 27 | for x in combinations: 28 | sums = 0 29 | for i in range(len(x)): 30 | sums += (i+1) * x[i] 31 | all_sums.append(sums) 32 | return max(all_sums) 33 | 34 | if __name__ == '__main__': 35 | N = int(input()) 36 | arr = list(map(int,input().strip().split())) 37 | print (maxSumLikeTimeCoeff(arr,N)) -------------------------------------------------------------------------------- /LeadSquared/totalDistanceByStreetLights.py: -------------------------------------------------------------------------------- 1 | """ 2 | Coding Test - Round 1 3 | 4 | Given N street lights, and an array of tuples which signify the start and 5 | end distances of street covered by that street light. 6 | 7 | Find the total distance covered by all the street lights 8 | 9 | Ex:1 10 | N = 1 11 | arr = [(5,10)] 12 | Number of street lights = 1 13 | and distance covered by street light i is 5m to 10m which is 10-5 = 5m 14 | 15 | Ex:2 16 | N = 2 17 | arr = [(5,10),(8,12)] 18 | Number of street lights = 2 19 | street light 0 = 10 - 5 = 5 20 | street light 1 = 12 - 8 = 4 21 | common region = 10 - 8 = 2 22 | total distance = (5 + 4 - 2) = 7 23 | 24 | """ 25 | 26 | def total_distance(intervals): 27 | if not intervals: 28 | return 0 29 | if len(intervals) == 1: 30 | return abs(intervals[0][0] - intervals[0][1]) 31 | result = 0 32 | common = 0 33 | intervals = sorted(intervals,key=lambda x: x[0]) 34 | for i in range(len(intervals)): 35 | result += abs(intervals[i][0] - intervals[i][1]) 36 | for i in range(len(intervals)-1): 37 | if intervals[i][1] > intervals[i+1][0]: 38 | common += abs(intervals[i][1] - intervals[i+1][0]) 39 | result = abs(result - common) 40 | return result 41 | 42 | if __name__ == '__main__': 43 | arr1 = [(5,10)] 44 | print (total_distance(arr1)) 45 | arr2 = [(5,10),(8,12)] 46 | print (total_distance(arr2)) 47 | 48 | #subset testcase 49 | arr3 = [(2,9),(3,6)] 50 | print (total_distance(arr3)) -------------------------------------------------------------------------------- /MAQ_Software/Closet0s1s2s.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__=='__main__': 14 | t = int(input()) 15 | for i in range(t): 16 | n=int(input()) 17 | a=list(map(int,input().strip().split())) 18 | segragate012(a,n) 19 | print(*a) 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ''' Your task to is sort the array a of 0s,1s and 2s 24 | of size n. You dont need to return anything.''' 25 | def segragate012(a,n): 26 | #code here 27 | c0 = a.count(0) 28 | c1 = a.count(1) 29 | c2 = a.count(2) 30 | for i in range(c0): 31 | a[i] = 0 32 | for i in range(c0,c0+c1): 33 | a[i] = 1 34 | for i in range(c0+c1,c0+c1+c2): 35 | a[i] = 2 36 | #print (" ".join(str(i) for i in a),end="") -------------------------------------------------------------------------------- /MakeMyTrip/rotateLinkedListByKelements.py: -------------------------------------------------------------------------------- 1 | { 2 | class Node: 3 | def __init__(self, data): 4 | self.data = data 5 | self.next = None 6 | class LinkedList: 7 | def __init__(self): 8 | self.head = None 9 | def push(self, new_data): 10 | new_node = Node(new_data) 11 | new_node.next = self.head 12 | self.head = new_node 13 | def printList(self): 14 | temp = self.head 15 | while(temp): 16 | print(temp.data, end=" ") 17 | # arr.append(str(temp.data)) 18 | temp = temp.next 19 | print("") 20 | if __name__ == '__main__': 21 | start = LinkedList() 22 | t = int(input()) 23 | while(t > 0): 24 | llist = LinkedList() 25 | n = int(input()) 26 | values = list(map(int, input().strip().split())) 27 | for i in reversed(values): 28 | llist.push(i) 29 | k = int(input()) 30 | new_head = rotateList(llist.head, k) 31 | llist.head = new_head 32 | llist.printList() 33 | t -= 1 34 | # Contributed by: Harshit Sidhwa 35 | 36 | } 37 | ''' This is a function problem.You only need to complete the function given below ''' 38 | # Your task is to complete this function 39 | ''' 40 | class Node: 41 | def __init__(self, data): 42 | self.data = data 43 | self.next = None 44 | ''' 45 | # This function should rotate list counter- 46 | # clockwise by k and return new head (if changed) 47 | def rotateList(head, k): 48 | # code here 49 | global llist 50 | llist = LinkedList() 51 | C = 0 52 | curr_node = head 53 | part1 = [] 54 | part2 = [] 55 | while curr_node != None: 56 | if C <= k-1: 57 | part1.append(curr_node.data) 58 | elif C > k-1: 59 | part2.append(curr_node.data) 60 | C += 1 61 | curr_node = curr_node.next 62 | total = reversed(part2 + part1) 63 | for i in total: 64 | llist.push(i) 65 | return llist.head -------------------------------------------------------------------------------- /MakeMyTrip/sortedLinkedList012s.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | # Node Class 15 | class Node: 16 | def __init__(self, data): # data -> value stored in node 17 | self.data = data 18 | self.next = None 19 | # Linked List Class 20 | class LinkedList: 21 | def __init__(self): 22 | self.head = None 23 | # creates a new node with given value and appends it at the end of the linked list 24 | def append(self, new_value): 25 | new_node = Node(new_value) 26 | if self.head is None: 27 | self.head = new_node 28 | return 29 | curr_node = self.head 30 | while curr_node.next is not None: 31 | curr_node = curr_node.next 32 | curr_node.next = new_node 33 | # prints the elements of linked list starting with head 34 | def printList(head): 35 | if head is None: 36 | print(' ') 37 | return 38 | curr_node = head 39 | while curr_node: 40 | print(curr_node.data,end=" ") 41 | curr_node=curr_node.next 42 | print(' ') 43 | if __name__ == '__main__': 44 | t=int(input()) 45 | for cases in range(t): 46 | n = int(input()) 47 | a = LinkedList() # create a new linked list 'a'. 48 | nodes_a = list(map(int, input().strip().split())) 49 | for x in nodes_a: 50 | a.append(x) # add to the end of the list 51 | printList(segregate(a.head)) 52 | } 53 | ''' This is a function problem.You only need to complete the function given below ''' 54 | #User function Template for python3 55 | ''' 56 | Your task is to segregate the list of 57 | 0s,1s and 2s. 58 | 59 | Function Arguments: head of the original list. 60 | Return Type: head of the new list formed. 61 | { 62 | # Node Class 63 | class Node: 64 | def __init__(self, data): # data -> value stored in node 65 | self.data = data 66 | self.next = None 67 | } 68 | Contributed By: Nagendra Jha 69 | ''' 70 | def segregate(head): 71 | #code here 72 | global a 73 | a = LinkedList() 74 | curr_node = head 75 | mylist = [] 76 | while curr_node != None: 77 | mylist.append(curr_node.data) 78 | curr_node = curr_node.next 79 | mylist = sorted(mylist) 80 | for i in mylist: 81 | a.append(i) 82 | return a.head -------------------------------------------------------------------------------- /Mastek/README.md: -------------------------------------------------------------------------------- 1 | Consider the below employee table where ManagerID is mapped to each EmployeeID: 2 | 3 | Input: 4 | | EmployeeID | EmployeeName | ManagerID | 5 | |------------|--------------|-----------| 6 | | 400     | A1    | null | 7 | | 401     | A2     | 400 | 8 | | 500     | A3     | 401 | 9 | | 501     | A4    | 401 | 10 | | 502     | A5 | 501 | 11 | 12 | Write the SQL query that identifies the level of each manager as mentioned in the below output: 13 | 14 | | EmployeeID | EmployeeName | ManagerID | Level | 15 | |------------|--------------|-----------|-------| 16 | | 400      | A1    | null    | 0 | 17 | | 401      | A2     | 400     | 1 | 18 | | 500      | A3     | 401     | 2 | 19 | | 501      | A4    | 401     | 2 | 20 | | 502     | A5    | 501     | 3 | 21 | 22 | 23 | ### Solution: 24 | 400 25 | | 26 | 401 (depth from 400 = 1) 27 | / \ 28 | 500 501 (depth from 400 = 2) 29 | \ 30 | 502 (depth from 400 = 3) 31 | 32 | 400 -> 401 33 | 401 -> 500, 501 34 | 501 -> 502 35 | 36 | **What we want to do here is use RECURSIVE CTE to traverse the tree in SQL and compute the depth at every level.** 37 | -------------------------------------------------------------------------------- /Mastek/computedepth.sql: -------------------------------------------------------------------------------- 1 | -- Oracle solution 2 | 3 | WITH RecursiveCTE (lvl, ManagerID, EmployeeID) AS ( 4 | SELECT 1 AS lvl, ManagerID, EmployeeID 5 | FROM employees 6 | WHERE ManagerID IS NULL 7 | UNION ALL 8 | SELECT lvl + 1, employees.ManagerID, employees.EmployeeID 9 | FROM employees 10 | JOIN RecursiveCTE 11 | ON employees.ManagerID = RecursiveCTE.EmployeeID 12 | ) 13 | SELECT * FROM RecursiveCTE; 14 | -------------------------------------------------------------------------------- /Microsoft/countOfInversionsArray.py: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks Code - Copied# 2 | { 3 | #Initial Template for Python 3 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__=='__main__': 15 | t = int(input()) 16 | for tt in range(t): 17 | n = int(input()) 18 | a = list(map(int, input().strip().split())) 19 | print(Inversion_Count(a,n)) 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ''' 24 | Your task is to return total number of inversions 25 | present in the array. 26 | 27 | Function Arguments: array a and size n 28 | Return Type: Integer 29 | ''' 30 | def Inversion_Count(arr,n): 31 | if a == sorted(a): 32 | return 0 33 | temp_arr = [0]*n 34 | return mergesort(arr,temp_arr,0,n-1) 35 | 36 | def mergesort(arr,temp_arr,left,right): 37 | inv_count = 0 38 | if left < right: 39 | mid = (left + right)//2 40 | inv_count = mergesort(arr,temp_arr,left,mid) 41 | inv_count += mergesort(arr,temp_arr,mid+1,right) 42 | inv_count += merge(arr,temp_arr,left,mid,right) 43 | return inv_count 44 | 45 | def merge(arr,temp_arr,left, mid, right): 46 | # Merge the temp arrays back into arr[l..r] 47 | i = left # Initial index of first subarray 48 | j = mid+1 # Initial index of second subarray 49 | k = left # Initial index of merged subarray 50 | invcount = 0 51 | while i <= mid and j <= right: 52 | if arr[i] <= arr[j]: 53 | temp_arr[k] = arr[i] 54 | i += 1 55 | else: 56 | temp_arr[k] = arr[j] 57 | invcount += (mid - i + 1) 58 | j += 1 59 | k += 1 60 | # Copy the remaining elements of L[], if there 61 | # are any 62 | while i <= mid: 63 | temp_arr[k] = arr[i] 64 | i += 1 65 | k += 1 66 | # Copy the remaining elements of R[], if there 67 | # are any 68 | while j <= right: 69 | temp_arr[k] = arr[j] 70 | j += 1 71 | k += 1 72 | 73 | for lr in range(left, right + 1): 74 | arr[lr] = temp_arr[lr] 75 | return invcount 76 | -------------------------------------------------------------------------------- /Microsoft/merge2SortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | # Node Class 4 | class Node: 5 | def __init__(self, data): # data -> value stored in node 6 | self.data = data 7 | self.next = None 8 | # Linked List Class 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | # creates a new node with given value and appends it at the end of the linked list 13 | def append(self, new_value): 14 | new_node = Node(new_value) 15 | if self.head is None: 16 | self.head = new_node 17 | return 18 | curr_node = self.head 19 | while curr_node.next is not None: 20 | curr_node = curr_node.next 21 | curr_node.next = new_node 22 | # prints the elements of linked list starting with head 23 | def printList(self): 24 | if self.head is None: 25 | print(' ') 26 | return 27 | curr_node = self.head 28 | while curr_node: 29 | print(curr_node.data,end=" ") 30 | curr_node=curr_node.next 31 | print(' ') 32 | if __name__ == '__main__': 33 | t=int(input()) 34 | for cases in range(t): 35 | n,m = map(int, input().strip().split()) 36 | a = LinkedList() # create a new linked list 'a'. 37 | b = LinkedList() # create a new linked list 'b'. 38 | nodes_a = list(map(int, input().strip().split())) 39 | nodes_b = list(map(int, input().strip().split())) 40 | for x in nodes_a: 41 | a.append(x) 42 | for x in nodes_b: 43 | b.append(x) 44 | a.head = merge(a.head,b.head) 45 | a.printList() 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | #User function Template for python3 49 | ''' 50 | Function to merge two sorted lists in one 51 | using constant space. 52 | 53 | Function Arguments: head_a and head_b (head reference of both the sorted lists) 54 | Return Type: head of the obtained list after merger. 55 | { 56 | # Node Class 57 | class Node: 58 | def __init__(self, data): # data -> value stored in node 59 | self.data = data 60 | self.next = None 61 | } 62 | Contributed By: Nagendra Jha 63 | ''' 64 | def merge(head_a,head_b): 65 | #code here 66 | global a 67 | elements = [] 68 | curr_node = head_a 69 | while curr_node != None: 70 | elements.append(curr_node.data) 71 | curr_node = curr_node.next 72 | curr_node = head_b 73 | while curr_node != None: 74 | elements.append(curr_node.data) 75 | curr_node = curr_node.next 76 | elements = sorted(elements) 77 | a = LinkedList() 78 | for i in elements: 79 | a.append(i) 80 | return a.head -------------------------------------------------------------------------------- /Microsoft/relativeSorting.py: -------------------------------------------------------------------------------- 1 | def relativeSorting(A1,A2): 2 | common_elements = set(A1).intersection(set(A2)) 3 | extra = set(A1).difference(set(A2)) 4 | out = [] 5 | for i in A2: 6 | s = [i] * A1.count(i) 7 | out.extend(s) 8 | extra_out = [] 9 | for j in extra: 10 | u = [j] * A1.count(j) 11 | extra_out.extend(u) 12 | out = out + sorted(extra_out) 13 | return " ".join(str(i) for i in out) 14 | 15 | if __name__ == '__main__': 16 | t = int(input()) 17 | for tcase in range(t): 18 | N,M = list(map(int,input().strip().split())) 19 | A1 = list(map(int,input().strip().split())) 20 | A2 = list(map(int,input().strip().split())) 21 | print (relativeSorting(A1,A2)) -------------------------------------------------------------------------------- /Morgan-Stanley/addTwoNumbers_LinkedListRep.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(head): 36 | if head is None: 37 | print(' ') 38 | return 39 | curr_node = head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | if __name__ == '__main__': 45 | t=int(input()) 46 | for cases in range(t): 47 | n_a = int(input()) 48 | a = LinkedList() # create a new linked list 'a'. 49 | nodes_a = list(map(int, input().strip().split())) 50 | nodes_a = nodes_a[::-1] # reverse the input array 51 | for x in nodes_a: 52 | a.append(x) # add to the end of the list 53 | n_b =int(input()) 54 | b = LinkedList() # create a new linked list 'b'. 55 | nodes_b = list(map(int, input().strip().split())) 56 | nodes_b = nodes_b[::-1] # reverse the input array 57 | for x in nodes_b: 58 | b.append(x) # add to the end of the list 59 | result_head = addBoth(a.head,b.head) 60 | printList(result_head) 61 | } 62 | ''' This is a function problem.You only need to complete the function given below ''' 63 | #User function Template for python3 64 | ''' 65 | Function to add two numbers represented 66 | in the form of the linked list. 67 | 68 | Function Arguments: head_a and head_b (heads of both the linked lists) 69 | Return Type: head of the resultant linked list. 70 | 71 | __>IMP : numbers are represented in reverse in the linked list. 72 | Ex: 73 | 145 is represented as 5->4->1. 74 | 75 | resultant head is expected in the same format. 76 | 77 | # Node Class 78 | class Node: 79 | def __init__(self, data): # data -> value stored in node 80 | self.data = data 81 | self.next = None 82 | ''' 83 | def addBoth(head_a,head_b): 84 | #code here 85 | result = LinkedList() 86 | num1 = "" 87 | curr_node = head_a 88 | while curr_node != None: 89 | num1 += str(curr_node.data) 90 | curr_node = curr_node.next 91 | num1 = num1[::-1] 92 | num2 = "" 93 | curr_node = head_b 94 | while curr_node != None: 95 | num2 += str(curr_node.data) 96 | curr_node = curr_node.next 97 | num2 = num2[::-1] 98 | num = int(num1) + int(num2) 99 | num = str(num)[::-1] 100 | for i in num: 101 | result.append(i) 102 | return result.head -------------------------------------------------------------------------------- /Myntra/countOfInversionsArray.py: -------------------------------------------------------------------------------- 1 | # GeeksForGeeks Code - Copied# 2 | { 3 | #Initial Template for Python 3 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__=='__main__': 15 | t = int(input()) 16 | for tt in range(t): 17 | n = int(input()) 18 | a = list(map(int, input().strip().split())) 19 | print(Inversion_Count(a,n)) 20 | } 21 | ''' This is a function problem.You only need to complete the function given below ''' 22 | #User function Template for python3 23 | ''' 24 | Your task is to return total number of inversions 25 | present in the array. 26 | 27 | Function Arguments: array a and size n 28 | Return Type: Integer 29 | ''' 30 | def Inversion_Count(arr,n): 31 | if a == sorted(a): 32 | return 0 33 | temp_arr = [0]*n 34 | return mergesort(arr,temp_arr,0,n-1) 35 | 36 | def mergesort(arr,temp_arr,left,right): 37 | inv_count = 0 38 | if left < right: 39 | mid = (left + right)//2 40 | inv_count = mergesort(arr,temp_arr,left,mid) 41 | inv_count += mergesort(arr,temp_arr,mid+1,right) 42 | inv_count += merge(arr,temp_arr,left,mid,right) 43 | return inv_count 44 | 45 | def merge(arr,temp_arr,left, mid, right): 46 | # Merge the temp arrays back into arr[l..r] 47 | i = left # Initial index of first subarray 48 | j = mid+1 # Initial index of second subarray 49 | k = left # Initial index of merged subarray 50 | invcount = 0 51 | while i <= mid and j <= right: 52 | if arr[i] <= arr[j]: 53 | temp_arr[k] = arr[i] 54 | i += 1 55 | else: 56 | temp_arr[k] = arr[j] 57 | invcount += (mid - i + 1) 58 | j += 1 59 | k += 1 60 | # Copy the remaining elements of L[], if there 61 | # are any 62 | while i <= mid: 63 | temp_arr[k] = arr[i] 64 | i += 1 65 | k += 1 66 | # Copy the remaining elements of R[], if there 67 | # are any 68 | while j <= right: 69 | temp_arr[k] = arr[j] 70 | j += 1 71 | k += 1 72 | 73 | for lr in range(left, right + 1): 74 | arr[lr] = temp_arr[lr] 75 | return invcount 76 | -------------------------------------------------------------------------------- /Myntra/removeDuplicatesSortedLinkedList.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(self): 36 | if self.head is None: 37 | print(' ') 38 | return 39 | curr_node = self.head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | 45 | if __name__ == '__main__': 46 | t=int(input()) 47 | for cases in range(t): 48 | n = int(input()) 49 | a = LinkedList() # create a new linked list 'a'. 50 | nodes = list(map(int, input().strip().split())) 51 | for x in nodes: 52 | a.append(x) 53 | removeDuplicates(a.head) 54 | a.printList() 55 | } 56 | ''' This is a function problem.You only need to complete the function given below ''' 57 | #User function Template for python3 58 | ''' 59 | Your task is to remove duplicates from given 60 | sorted linked list. 61 | 62 | Function Arguments: head (head of the given linked list) 63 | Return Type: none, just remove the duplicates from the list. 64 | { 65 | # Node Class 66 | class Node: 67 | def __init__(self, data): # data -> value stored in node 68 | self.data = data 69 | self.next = None 70 | } 71 | ''' 72 | def removeDuplicates(head): 73 | #code here 74 | global a 75 | curr_node = head 76 | duplicateTracker = [] 77 | while curr_node != None: 78 | if curr_node.data not in duplicateTracker: 79 | duplicateTracker.append(curr_node.data) 80 | curr_node = curr_node.next 81 | a = LinkedList() 82 | for x in duplicateTracker: 83 | a.append(x) -------------------------------------------------------------------------------- /Nagarro/isAnagram.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__=='__main__': 14 | t = int(input()) 15 | for i in range(t): 16 | a,b=map(str,input().strip().split()) 17 | if(isAnagram(a,b)): 18 | print("YES") 19 | else: 20 | print("NO") 21 | } 22 | ''' This is a function problem.You only need to complete the function given below ''' 23 | #User function Template for python3 24 | '''Your task is to check given two strings 25 | are anagrams or not. 26 | a,b: given strings 27 | 28 | Return True or False accordingly. 29 | 30 | -> You don't need to print anything.Return type of function 31 | is boolean. 32 | ''' 33 | def isAnagram(a,b): 34 | #code here 35 | import collections 36 | freqs_a = collections.Counter(a) 37 | freqs_b = collections.Counter(b) 38 | if (set(a) == set(b)) and (sorted(freqs_a.values()) == sorted(freqs_b.values())): 39 | return True 40 | else: 41 | return False -------------------------------------------------------------------------------- /OYO_Rooms/FindzeroSumSubArrays.py: -------------------------------------------------------------------------------- 1 | def subArrayExists(arr,n): 2 | ##Your code here 3 | hashMap = {} 4 | out = [] 5 | sum1 = 0 6 | for i in range(n): 7 | sum1 += arr[i] 8 | if sum1==0: 9 | out.append((0,i)) 10 | al = [] 11 | if sum1 in hashMap: 12 | al = hashMap.get(sum1) 13 | for it in range(len(al)): 14 | out.append((al[it]+1,i)) 15 | al.append(i) 16 | hashMap[sum1] = al 17 | return len(out) 18 | 19 | 20 | if __name__ == '__main__': 21 | t = int(input()) 22 | for tcase in range(t): 23 | n = int(input()) 24 | arr = list(map(int,input().strip().split())) 25 | print (subArrayExists(arr,n)) -------------------------------------------------------------------------------- /OYO_Rooms/parenthesisChecker.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | #Contributed by : Nagendra Jha 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__ == '__main__': 15 | test_cases = int(input()) 16 | for cases in range(test_cases) : 17 | #n = int(input()) 18 | #n,k = map(int,imput().strip().split()) 19 | #a = list(map(int,input().strip().split())) 20 | s = str(input()) 21 | if ispar(s): 22 | print("balanced") 23 | else: 24 | print("not balanced") 25 | } 26 | ''' This is a function problem.You only need to complete the function given below ''' 27 | #User function Template for python3 28 | ''' 29 | Function Arguments : 30 | @param : s (given string containing parenthesis) 31 | @return : boolean True or False 32 | ''' 33 | 34 | def isMatchingPair(c1,c2): 35 | if (c1=='(') & (c2==')'): 36 | return True 37 | elif (c1=='{') & (c2=='}'): 38 | return True 39 | elif (c1=='[') & (c2==']'): 40 | return True 41 | else: 42 | return False 43 | 44 | def ispar(s): 45 | # code here 46 | import queue 47 | stack = queue.LifoQueue() 48 | 49 | for i in range(len(s)): 50 | if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')): 51 | stack.put(s[i]) 52 | if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')): 53 | if stack.empty(): 54 | return False 55 | elif not isMatchingPair(stack.get(),s[i]): 56 | return False 57 | 58 | if stack.empty(): 59 | return True 60 | else: 61 | return False -------------------------------------------------------------------------------- /OYO_Rooms/removeDuplicatesSortedLinkedList.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(self): 36 | if self.head is None: 37 | print(' ') 38 | return 39 | curr_node = self.head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | 45 | if __name__ == '__main__': 46 | t=int(input()) 47 | for cases in range(t): 48 | n = int(input()) 49 | a = LinkedList() # create a new linked list 'a'. 50 | nodes = list(map(int, input().strip().split())) 51 | for x in nodes: 52 | a.append(x) 53 | removeDuplicates(a.head) 54 | a.printList() 55 | } 56 | ''' This is a function problem.You only need to complete the function given below ''' 57 | #User function Template for python3 58 | ''' 59 | Your task is to remove duplicates from given 60 | sorted linked list. 61 | 62 | Function Arguments: head (head of the given linked list) 63 | Return Type: none, just remove the duplicates from the list. 64 | { 65 | # Node Class 66 | class Node: 67 | def __init__(self, data): # data -> value stored in node 68 | self.data = data 69 | self.next = None 70 | } 71 | ''' 72 | def removeDuplicates(head): 73 | #code here 74 | global a 75 | curr_node = head 76 | duplicateTracker = [] 77 | while curr_node != None: 78 | if curr_node.data not in duplicateTracker: 79 | duplicateTracker.append(curr_node.data) 80 | curr_node = curr_node.next 81 | a = LinkedList() 82 | for x in duplicateTracker: 83 | a.append(x) -------------------------------------------------------------------------------- /Oracle/merge2SortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | # Node Class 4 | class Node: 5 | def __init__(self, data): # data -> value stored in node 6 | self.data = data 7 | self.next = None 8 | # Linked List Class 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | # creates a new node with given value and appends it at the end of the linked list 13 | def append(self, new_value): 14 | new_node = Node(new_value) 15 | if self.head is None: 16 | self.head = new_node 17 | return 18 | curr_node = self.head 19 | while curr_node.next is not None: 20 | curr_node = curr_node.next 21 | curr_node.next = new_node 22 | # prints the elements of linked list starting with head 23 | def printList(self): 24 | if self.head is None: 25 | print(' ') 26 | return 27 | curr_node = self.head 28 | while curr_node: 29 | print(curr_node.data,end=" ") 30 | curr_node=curr_node.next 31 | print(' ') 32 | if __name__ == '__main__': 33 | t=int(input()) 34 | for cases in range(t): 35 | n,m = map(int, input().strip().split()) 36 | a = LinkedList() # create a new linked list 'a'. 37 | b = LinkedList() # create a new linked list 'b'. 38 | nodes_a = list(map(int, input().strip().split())) 39 | nodes_b = list(map(int, input().strip().split())) 40 | for x in nodes_a: 41 | a.append(x) 42 | for x in nodes_b: 43 | b.append(x) 44 | a.head = merge(a.head,b.head) 45 | a.printList() 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | #User function Template for python3 49 | ''' 50 | Function to merge two sorted lists in one 51 | using constant space. 52 | 53 | Function Arguments: head_a and head_b (head reference of both the sorted lists) 54 | Return Type: head of the obtained list after merger. 55 | { 56 | # Node Class 57 | class Node: 58 | def __init__(self, data): # data -> value stored in node 59 | self.data = data 60 | self.next = None 61 | } 62 | Contributed By: Nagendra Jha 63 | ''' 64 | def merge(head_a,head_b): 65 | #code here 66 | global a 67 | elements = [] 68 | curr_node = head_a 69 | while curr_node != None: 70 | elements.append(curr_node.data) 71 | curr_node = curr_node.next 72 | curr_node = head_b 73 | while curr_node != None: 74 | elements.append(curr_node.data) 75 | curr_node = curr_node.next 76 | elements = sorted(elements) 77 | a = LinkedList() 78 | for i in elements: 79 | a.append(i) 80 | return a.head -------------------------------------------------------------------------------- /Paytm/Convert_Infix_To_Postfix.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | # This code is contributed by Nikhil Kumar Singh(nickzuck_007) 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__ == '__main__': 15 | test_cases = int(input()) 16 | for cases in range(test_cases) : 17 | exp = str(input()) 18 | print(InfixtoPostfix(exp)) 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | #User function Template for python3 22 | ''' 23 | Function Arguments : 24 | @param : exp (given infix expression) 25 | @return : string 26 | ''' 27 | def InfixtoPostfix(exp): 28 | #code here 29 | import string 30 | stack = [] 31 | prec = {'^':4,'*':3,'/':3,'+':2,'-':2,'(':1} 32 | postfixexp = [] 33 | tokens = list(exp) 34 | for token in tokens: 35 | if ((token in string.ascii_lowercase) | (token in "0123456789") | (token in string.ascii_uppercase)): 36 | postfixexp.append(token) 37 | elif token == '(': 38 | stack.append(token) 39 | elif token == ')': 40 | if len(stack)!=0: 41 | topToken = stack.pop() 42 | while topToken != '(': 43 | postfixexp.append(topToken) 44 | topToken = stack.pop() 45 | else: 46 | if len(stack) != 0: 47 | while (len(stack)!=0) and (prec[stack[-1]] >= prec[token]): 48 | postfixexp.append(stack.pop()) 49 | stack.append(token) 50 | while len(stack)!=0: 51 | postfixexp.append(stack.pop()) 52 | return "".join(postfixexp) -------------------------------------------------------------------------------- /Paytm/binaryArraySort.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | N=int(input()) 8 | A=list(map(int,input().split())) 9 | 10 | binSort(A,N) 11 | 12 | for i in A: 13 | print(i,end=" ") 14 | print() 15 | 16 | T-=1 17 | if __name__ == "__main__": 18 | main() 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | #User function Template for python3 22 | ##Complete this function 23 | def binSort(arr, n): 24 | #Your code here 25 | 26 | 27 | ''' 28 | No need to print the array 29 | ''' 30 | c0 = arr.count(0) 31 | c1 = arr.count(1) 32 | for i in range(c0): 33 | arr[i] = 0 34 | for i in range(c0,c0+c1): 35 | arr[i] = 1 -------------------------------------------------------------------------------- /Paytm/frequencyLimitedRangeArrayElements.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | 6 | T=int(input()) 7 | 8 | while(T>0): 9 | 10 | 11 | N=int(input()) 12 | 13 | A=[int(x) for x in input().strip().split()] 14 | printfrequency(A,N) 15 | 16 | print() 17 | 18 | T-=1 19 | if __name__=="__main__": 20 | main() 21 | } 22 | ''' This is a function problem.You only need to complete the function given below ''' 23 | #User function Template for python3 24 | #Complete this function 25 | def printfrequency(A,N): 26 | #Your Code here 27 | import collections 28 | freq_dict = collections.Counter(A) 29 | for i in range(1,N+1): 30 | print (freq_dict[i],end=" ") -------------------------------------------------------------------------------- /Paytm/subarrayWithZeroSum.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | def main(): 4 | T=int(input()) 5 | while(T>0): 6 | 7 | n=int(input()) 8 | arr=[int(x) for x in input().strip().split()] 9 | if(subArrayExists(arr,n)): 10 | print("Yes") 11 | else: 12 | print("No") 13 | 14 | 15 | T-=1 16 | if __name__=="__main__": 17 | main() 18 | } 19 | ''' This is a function problem.You only need to complete the function given below ''' 20 | #User function Template for python3 21 | #Complete this function 22 | 23 | def allSubArrays(L,L2=None): 24 | if L2==None: 25 | L2 = L[:-1] 26 | if L==[]: 27 | if L2==[]: 28 | return [] 29 | return allSubArrays(L2,L2[:-1]) 30 | return [L]+allSubArrays(L[1:],L2) 31 | 32 | def subArrayExists(arr,n): 33 | ##Your code here 34 | #Return true or false 35 | if 0 in arr: 36 | return True 37 | else: 38 | allsubarrays = allSubArrays(arr) 39 | for s in allsubarrays: 40 | if sum(s) == 0: 41 | return True 42 | return False -------------------------------------------------------------------------------- /Qalcomm/ImplementSTRSTR.py: -------------------------------------------------------------------------------- 1 | { 2 | #Contributed by : Nagendra Jha 3 | import atexit 4 | import io 5 | import sys 6 | _INPUT_LINES = sys.stdin.read().splitlines() 7 | input = iter(_INPUT_LINES).__next__ 8 | _OUTPUT_BUFFER = io.StringIO() 9 | sys.stdout = _OUTPUT_BUFFER 10 | @atexit.register 11 | def write(): 12 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 13 | if __name__ == '__main__': 14 | t=int(input()) 15 | for cases in range(t): 16 | s,p =input().strip().split() 17 | print(strstr(s,p)) 18 | 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | ''' 22 | Your task is to return the index of the pattern 23 | present in the given string. 24 | 25 | Function Arguments: s (given text), p(given pattern) 26 | Return Type: Integer. 27 | 28 | ''' 29 | def strstr(s,p): 30 | #code here 31 | import re 32 | loc = re.search(p,s) 33 | if loc is not None: 34 | return (loc.start()) 35 | else: 36 | return -1 -------------------------------------------------------------------------------- /Qalcomm/addTwoNumbers_LinkedListRep.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(head): 36 | if head is None: 37 | print(' ') 38 | return 39 | curr_node = head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | if __name__ == '__main__': 45 | t=int(input()) 46 | for cases in range(t): 47 | n_a = int(input()) 48 | a = LinkedList() # create a new linked list 'a'. 49 | nodes_a = list(map(int, input().strip().split())) 50 | nodes_a = nodes_a[::-1] # reverse the input array 51 | for x in nodes_a: 52 | a.append(x) # add to the end of the list 53 | n_b =int(input()) 54 | b = LinkedList() # create a new linked list 'b'. 55 | nodes_b = list(map(int, input().strip().split())) 56 | nodes_b = nodes_b[::-1] # reverse the input array 57 | for x in nodes_b: 58 | b.append(x) # add to the end of the list 59 | result_head = addBoth(a.head,b.head) 60 | printList(result_head) 61 | } 62 | ''' This is a function problem.You only need to complete the function given below ''' 63 | #User function Template for python3 64 | ''' 65 | Function to add two numbers represented 66 | in the form of the linked list. 67 | 68 | Function Arguments: head_a and head_b (heads of both the linked lists) 69 | Return Type: head of the resultant linked list. 70 | 71 | __>IMP : numbers are represented in reverse in the linked list. 72 | Ex: 73 | 145 is represented as 5->4->1. 74 | 75 | resultant head is expected in the same format. 76 | 77 | # Node Class 78 | class Node: 79 | def __init__(self, data): # data -> value stored in node 80 | self.data = data 81 | self.next = None 82 | ''' 83 | def addBoth(head_a,head_b): 84 | #code here 85 | result = LinkedList() 86 | num1 = "" 87 | curr_node = head_a 88 | while curr_node != None: 89 | num1 += str(curr_node.data) 90 | curr_node = curr_node.next 91 | num1 = num1[::-1] 92 | num2 = "" 93 | curr_node = head_b 94 | while curr_node != None: 95 | num2 += str(curr_node.data) 96 | curr_node = curr_node.next 97 | num2 = num2[::-1] 98 | num = int(num1) + int(num2) 99 | num = str(num)[::-1] 100 | for i in num: 101 | result.append(i) 102 | return result.head -------------------------------------------------------------------------------- /Quikr/BuySellStock.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | stockBuySell(arr,n) 12 | print() 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | #Complete this function 21 | def stockBuySell(A,n): 22 | if A == sorted(A): 23 | print ("(" + str(0) + " " + str(n-1) + ")",end=" ") 24 | elif A == sorted(A,reverse=True): 25 | print ("No Profit",end = " ") 26 | else: 27 | local_min = [] 28 | local_max = [] 29 | for i,v in enumerate(A): 30 | if i == 0: 31 | if v < A[i+1]: 32 | local_min.append(i) 33 | elif i == n-1: 34 | if v > A[i-1]: 35 | local_max.append(i) 36 | else: 37 | if A[i-1] <= v and v >= A[i+1]: 38 | local_max.append(i) 39 | if A[i-1] >= v and v <= A[i+1]: 40 | local_min.append(i) 41 | if len(local_max) == len(local_min): 42 | for i in range(len(local_max)): 43 | x = " ".join([str(local_min[i]),str(local_max[i])]) 44 | print ("("+x+")",end=" ") 45 | else: 46 | x = " ".join([str(max(local_min)),str(max(local_max))]) 47 | print ("("+x+")",end = " ") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming questions/Case studies/Theoretical questions/Design questions etc From Interviews and Coding Tests: 2 | 3 | + Interview Coding Questions for Several Companies encapsulated into one Repository. 4 | + Coding questions asked in private hiring processes. 5 | + Statistics and questions on Data science for Data scientist interviews. 6 | + Along with coding questions, interview procedures experienced are also included here. 7 | + **Please note that some of these questions are from my own experiences with various companies (check README for that information), please create an issue if you have any questions regarding any company and its questions.** 8 | + **I update this repo with additions as I go through the process of hiring (You can imagine this as kind of a blog), so sometimes even if I didn't make it till the end of the whole process you can expect the questions till the point I was there, My intention is to help the community of software developers.** 9 | + **This repository and [Coding Questions](https://github.com/absognety/Competitive-Coding-Platforms) can have few common questions** 10 | + Check out my effort in solving questions from daily coding problem (Daily coding quesitons sent to your email) at [Here](https://github.com/absognety/Competitive-Coding-Platforms/tree/master/DailyCodingProblem). 11 | 12 | Feel free to contribute to this repo and make this one of the best open source resources for interview preparations!!!! 13 | # Disclaimer: This repository might document the interview processes of latest up and coming companies which could lead to interview privacy concerns - I trust the user discretion for this. 14 | Please note that the interview questions and process bound to change at any point of time - but If this repository helped you, Please give a star. 15 | -------------------------------------------------------------------------------- /RelianceJIO/CamelCaseToSnakeCase.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3.8 2 | """ 3 | 4 | Write a function that converts camel_case string into snake case: 5 | 6 | Example: 7 | 8 | HackerEarth => hacker_earth 9 | OddOrEven => odd_or_even 10 | macOS => mac_o_s 11 | primeCheck => prime_check 12 | 13 | Explanation: 14 | Camel case string is string with uppercase and lowercase characters 15 | mixed up like illustrated above 16 | 17 | Snake case strings are lowercase with underscores in place of uppercase 18 | characters which are in the middle 19 | 20 | """ 21 | import re 22 | def convert_string(s:str) -> str: 23 | store_indices = [] 24 | slist = list(s) 25 | for ind,val in enumerate(s): 26 | if val.isupper() and ind!=0: 27 | store_indices.append(ind) 28 | 29 | c = len(store_indices) 30 | l = 0 31 | while (l <= c-1): 32 | slist.insert(store_indices[l]+l,'_') 33 | l += 1 34 | return ''.join(slist).lower() 35 | 36 | 37 | if __name__ == '__main__': 38 | for tcase in range(T:=int(input())): 39 | s = input() 40 | print (convert_string(s)) 41 | -------------------------------------------------------------------------------- /RelianceJIO/README.md: -------------------------------------------------------------------------------- 1 | # First round: 2 | ## Hackerrarth Test with some data science questions (Objective) along with 2 coding question 3 | -------------------------------------------------------------------------------- /RelianceJIO/getSmallestNumber.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3.8 2 | 3 | """ 4 | P(N) gives all the numbers that divide given number N 5 | 6 | find the smallest number number Y such that Y > X and P(Y) != P(X), given 7 | number X 8 | """ 9 | import math 10 | def div_count(n): 11 | # sieve method for 12 | # prime calculation 13 | hh = [1] * (n + 1); 14 | 15 | p = 2 16 | while((p * p) < n): 17 | if (hh[p] == 1): 18 | for i in range((p * 2), n, p): 19 | hh[i] = 0 20 | p += 1 21 | 22 | # Traversing through 23 | # all prime numbers 24 | total = 1 25 | for p in range(2, n + 1): 26 | if (hh[p] == 1): 27 | 28 | # calculate number of divisor 29 | # with formula total div = 30 | # (p1+1) * (p2+1) *.....* (pn+1) 31 | # where n = (a1^p1)*(a2^p2).... 32 | # *(an^pn) ai being prime divisor 33 | # for n and pi are their respective 34 | # power in factorization 35 | count = 0 36 | if (n % p == 0): 37 | while (n % p == 0): 38 | n = int(n / p) 39 | count += 1 40 | total *= (count + 1) 41 | 42 | return total 43 | 44 | 45 | def smallestNumber(n,ndn): 46 | MAX_INT = math.inf 47 | p = n + 1 48 | while (p < MAX_INT): 49 | if div_count(p) != ndn: 50 | break 51 | p += 1 52 | return p 53 | 54 | if __name__ == '__main__': 55 | for tcase in range(T:=int(input())): 56 | n = int(input()) 57 | print (smallestNumber(n, ndn=div_count(n))) -------------------------------------------------------------------------------- /Salesforce/BuySellStock.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | stockBuySell(arr,n) 12 | print() 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | #Complete this function 21 | def stockBuySell(A,n): 22 | if A == sorted(A): 23 | print ("(" + str(0) + " " + str(n-1) + ")",end=" ") 24 | elif A == sorted(A,reverse=True): 25 | print ("No Profit",end = " ") 26 | else: 27 | local_min = [] 28 | local_max = [] 29 | for i,v in enumerate(A): 30 | if i == 0: 31 | if v < A[i+1]: 32 | local_min.append(i) 33 | elif i == n-1: 34 | if v > A[i-1]: 35 | local_max.append(i) 36 | else: 37 | if A[i-1] <= v and v >= A[i+1]: 38 | local_max.append(i) 39 | if A[i-1] >= v and v <= A[i+1]: 40 | local_min.append(i) 41 | if len(local_max) == len(local_min): 42 | for i in range(len(local_max)): 43 | x = " ".join([str(local_min[i]),str(local_max[i])]) 44 | print ("("+x+")",end=" ") 45 | else: 46 | x = " ".join([str(max(local_min)),str(max(local_max))]) 47 | print ("("+x+")",end = " ") -------------------------------------------------------------------------------- /Samsung/merge2SortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | # Node Class 4 | class Node: 5 | def __init__(self, data): # data -> value stored in node 6 | self.data = data 7 | self.next = None 8 | # Linked List Class 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | # creates a new node with given value and appends it at the end of the linked list 13 | def append(self, new_value): 14 | new_node = Node(new_value) 15 | if self.head is None: 16 | self.head = new_node 17 | return 18 | curr_node = self.head 19 | while curr_node.next is not None: 20 | curr_node = curr_node.next 21 | curr_node.next = new_node 22 | # prints the elements of linked list starting with head 23 | def printList(self): 24 | if self.head is None: 25 | print(' ') 26 | return 27 | curr_node = self.head 28 | while curr_node: 29 | print(curr_node.data,end=" ") 30 | curr_node=curr_node.next 31 | print(' ') 32 | if __name__ == '__main__': 33 | t=int(input()) 34 | for cases in range(t): 35 | n,m = map(int, input().strip().split()) 36 | a = LinkedList() # create a new linked list 'a'. 37 | b = LinkedList() # create a new linked list 'b'. 38 | nodes_a = list(map(int, input().strip().split())) 39 | nodes_b = list(map(int, input().strip().split())) 40 | for x in nodes_a: 41 | a.append(x) 42 | for x in nodes_b: 43 | b.append(x) 44 | a.head = merge(a.head,b.head) 45 | a.printList() 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | #User function Template for python3 49 | ''' 50 | Function to merge two sorted lists in one 51 | using constant space. 52 | 53 | Function Arguments: head_a and head_b (head reference of both the sorted lists) 54 | Return Type: head of the obtained list after merger. 55 | { 56 | # Node Class 57 | class Node: 58 | def __init__(self, data): # data -> value stored in node 59 | self.data = data 60 | self.next = None 61 | } 62 | Contributed By: Nagendra Jha 63 | ''' 64 | def merge(head_a,head_b): 65 | #code here 66 | global a 67 | elements = [] 68 | curr_node = head_a 69 | while curr_node != None: 70 | elements.append(curr_node.data) 71 | curr_node = curr_node.next 72 | curr_node = head_b 73 | while curr_node != None: 74 | elements.append(curr_node.data) 75 | curr_node = curr_node.next 76 | elements = sorted(elements) 77 | a = LinkedList() 78 | for i in elements: 79 | a.append(i) 80 | return a.head -------------------------------------------------------------------------------- /Samsung/missingSmallestPositiveNumber.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | 12 | print(missingNumber(arr,n)) 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | ##Complete this function 21 | def missingNumber(arr,n): 22 | #Your code here 23 | poss = [x for x in arr if x > 0] 24 | if poss: 25 | if poss == list(range(1,n+1)): 26 | return max(poss)+1 27 | else: 28 | min_poss = min(poss) 29 | max_poss = max(poss) 30 | total_range = list(range(1,max_poss+1)) 31 | missingNumbers = set(total_range) - set(poss) 32 | return min(missingNumbers) 33 | else: 34 | return 0 -------------------------------------------------------------------------------- /Samsung/moveAllZerosToEndOfArray.py: -------------------------------------------------------------------------------- 1 | def moveZerosToEnd(arr): 2 | arr_0 = [x for x in arr if x!=0] 3 | zeros = [0] * (len(arr)-len(arr_0)) 4 | ans = arr_0 + zeros 5 | return " ".join(str(u) for u in ans) 6 | 7 | if __name__ == '__main__': 8 | T = int(input()) 9 | for t in range(T): 10 | N = int(input()) 11 | arr = list(map(int,input().strip().split())) 12 | print (moveZerosToEnd(arr)) -------------------------------------------------------------------------------- /SkyPointCloud/README.md: -------------------------------------------------------------------------------- 1 | # Interview process for skypoint cloud (Data engineer) (Personal Experience): 2 | 1. **Hackerearth Test**: objective questions on hadoop, spark, python and airflow basics and one coding question added above. 3 | 2. **First round of Interview**: 4 | - Questions: 5 | - what is the difference between mapreduce and spark? 6 | - What is the difference between Spark `coalesce` and `repartition`? 7 | - How do you handle out of memory error in spark application execution? 8 | - How does pyspark work? 9 | - Can you explain how you solved the programming question you have solved in the test? (refer [here](https://github.com/absognety/Interview-Process-Coding-Questions/blob/master/SkyPointCloud/modifyString.py)) 10 | 3. **Second round of Interview**: 11 | - Questions: 12 | - what are the challenges you encountered in your projects and how did you solve them? 13 | - **Case Study**: 14 | - Let's say there are 3 data sources(RDBMS), First Data source contains (firstname,lastname,email and gender), second one contains (firstname,lastname,order_history) and third contains (email,profile_id). How can you construct a 360 degrees view of a customer that contains all information from 3 data sources containing (firstname,lastname,email,gender,order_history and profile_id) but without traditional way of joining the columns (looking for more of ML based solution)(Hint: the columns may contain special characters, spaces, underscores etc) 15 | - What are list comprehensions and dictionary comprehensions in python. 16 | - Tell me one approach on finding all prime numbers in the given range? 17 | - Can you code up a binary search algorithm in array that is sorted in descending order? (refer [here](https://github.com/absognety/Interview-Process-Coding-Questions/blob/master/SkyPointCloud/binarySearch.py)) 18 | - How do you define/create a class in python? 19 | 4. **Final round of interview with Founder/CEO**. 20 | -------------------------------------------------------------------------------- /SkyPointCloud/binarySearch.py: -------------------------------------------------------------------------------- 1 | """ 2 | Can you write the binary search algorithm for reverse sorted array? 3 | 4 | """ 5 | def binarySearch(arr,x): 6 | arr = sorted(arr,reverse=True) 7 | l = 0 8 | r = len(arr) - 1 9 | 10 | while l <= r: 11 | 12 | mid = l + (r - l) // 2; 13 | 14 | # Check if x is present at mid 15 | if arr[mid] == x: 16 | return mid 17 | 18 | elif arr[mid] > x: 19 | l = mid + 1 20 | 21 | else: 22 | r = mid - 1 23 | 24 | # If we reach here, then the element 25 | # was not present 26 | return "not present" 27 | 28 | if __name__ == '__main__': 29 | mylist = [1,3,5,7,9,8,5,88,79] 30 | n = len(mylist) 31 | print (binarySearch(mylist,5)) 32 | print (binarySearch(mylist,88)) 33 | print (binarySearch(mylist,79)) 34 | print (binarySearch(mylist,20)) 35 | print (binarySearch(mylist,1)) -------------------------------------------------------------------------------- /SkyPointCloud/modifyString.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a string, sort/modify the characters of string according to below rules: 3 | 4 | 1. characters having prime ascii values should come before characters 5 | having composite ascii values. 6 | 7 | 2. if two characters have same prime ascii value, then the character with 8 | less value should come first. 9 | 10 | 3. if two characters have same composite ascii value, then the character 11 | with greater value should come first 12 | 13 | """ 14 | 15 | def isPrime(n) : 16 | 17 | # Corner cases 18 | if (n <= 1) : 19 | return False 20 | if (n <= 3) : 21 | return True 22 | 23 | # This is checked so that we can skip 24 | # middle five numbers in below loop 25 | if (n % 2 == 0 or n % 3 == 0) : 26 | return False 27 | 28 | i = 5 29 | while(i * i <= n) : 30 | if (n % i == 0 or n % (i + 2) == 0) : 31 | return False 32 | i = i + 6 33 | 34 | return True 35 | 36 | def sort_string(s,n): 37 | prime_chars = [] 38 | composite_chars = [] 39 | for c in s: 40 | if isPrime(ord(c)): 41 | prime_chars.append(c) 42 | else: 43 | composite_chars.append(c) 44 | prime_dict = [(c,ord(c)) for c in prime_chars] 45 | composite_dict = [(d,ord(d)) for d in composite_chars] 46 | prime_dict = sorted(prime_dict,key=lambda x: x[1]) 47 | composite_dict = sorted(composite_dict,key=lambda y:y[1],reverse=True) 48 | result = [k1 for k1,v1 in prime_dict] + [k2 for k2,v2 in composite_dict] 49 | return ''.join(result) 50 | 51 | if __name__ == '__main__': 52 | n = int(input()) 53 | s = input() 54 | print (sort_string(s,n)) -------------------------------------------------------------------------------- /Snapdeal/addTwoNumbers_LinkedListRep.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(head): 36 | if head is None: 37 | print(' ') 38 | return 39 | curr_node = head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | if __name__ == '__main__': 45 | t=int(input()) 46 | for cases in range(t): 47 | n_a = int(input()) 48 | a = LinkedList() # create a new linked list 'a'. 49 | nodes_a = list(map(int, input().strip().split())) 50 | nodes_a = nodes_a[::-1] # reverse the input array 51 | for x in nodes_a: 52 | a.append(x) # add to the end of the list 53 | n_b =int(input()) 54 | b = LinkedList() # create a new linked list 'b'. 55 | nodes_b = list(map(int, input().strip().split())) 56 | nodes_b = nodes_b[::-1] # reverse the input array 57 | for x in nodes_b: 58 | b.append(x) # add to the end of the list 59 | result_head = addBoth(a.head,b.head) 60 | printList(result_head) 61 | } 62 | ''' This is a function problem.You only need to complete the function given below ''' 63 | #User function Template for python3 64 | ''' 65 | Function to add two numbers represented 66 | in the form of the linked list. 67 | 68 | Function Arguments: head_a and head_b (heads of both the linked lists) 69 | Return Type: head of the resultant linked list. 70 | 71 | __>IMP : numbers are represented in reverse in the linked list. 72 | Ex: 73 | 145 is represented as 5->4->1. 74 | 75 | resultant head is expected in the same format. 76 | 77 | # Node Class 78 | class Node: 79 | def __init__(self, data): # data -> value stored in node 80 | self.data = data 81 | self.next = None 82 | ''' 83 | def addBoth(head_a,head_b): 84 | #code here 85 | result = LinkedList() 86 | num1 = "" 87 | curr_node = head_a 88 | while curr_node != None: 89 | num1 += str(curr_node.data) 90 | curr_node = curr_node.next 91 | num1 = num1[::-1] 92 | num2 = "" 93 | curr_node = head_b 94 | while curr_node != None: 95 | num2 += str(curr_node.data) 96 | curr_node = curr_node.next 97 | num2 = num2[::-1] 98 | num = int(num1) + int(num2) 99 | num = str(num)[::-1] 100 | for i in num: 101 | result.append(i) 102 | return result.head -------------------------------------------------------------------------------- /Swiggy/README.md: -------------------------------------------------------------------------------- 1 | # Personal Experience - Software Development Engineer - II (Data and ML Platform): 2 | 3 | ## First Round (Computer Science Fundamentals and DSA): 4 | - Let's assume there are N number of lines in 2D coordinate system and their start and end points - `(X1s,X1e),(X2s,X2e),......(XNs,XNe) where s = start and e = end`, we need to draw a line perpendicular to X-axis (Parallel to Y-axis) such that the line intersects maximum number of given lines and also find the points of intersection if possible (If multiple intersection points possible that maximizes number of intersections - return any of them). 5 | - Find the second largest element in an array? 6 | - When does the shuffling happen in spark? 7 | - what's your inference on the scenario where the application is running and memory consumption is too high and CPU utilization is constant? 8 | - what are `coalesce` and `repartition` in Spark? 9 | - How does the parallelism happen in Python? Methods to deal with and questions on relevant libraries? 10 | 11 | ## Second Round (DSA): 12 | - Code up a linkedlist with all necessary operations from scratch! 13 | - Questions on developed linkedlist code, execution and manipulations to the code for some questions. 14 | - Find the middle element of the linkedlist. 15 | - Detect a cycle in the linkedlist if present. 16 | - Doubly linkedlists and cyclic linkedlists - Questions only (No need to implement). 17 | - Questions on Internals of Spark and performance related questions. 18 | 19 | ## LLD (Low Level Design Round): 20 | - Given a scenario of ATC (Air Traffic Controller) and flights, Questions on interactions between flight pilot and ATC if ATC needs to replaced with a automated system (Answer expected interms of API lingo) - payload, messages exchange, queues, parameters - etc. 21 | - Design a low level ATC system that manages the flight traffic, departures and arrivals within 50 kms of radius. 22 | -------------------------------------------------------------------------------- /SymphonyAI/README.md: -------------------------------------------------------------------------------- 1 | Hackerrank Test (Personal Experience) (2020) 2 | =========================================== 3 | ______________________________________________________________________________________________ 4 | 5 | # Interview Experience (NLP Systems Engineer) - 2021: 6 | ### First Round: 7 | + Simple programming and statistics based questions using numpy,scipy etc. 8 | + Quesitons on pyspark vs scala-spark 9 | + what kind of Data warehouse architecture are you using in your company? Questions on that as well. 10 | 11 | ### Second Round: 12 | + Random forest vs XGBoost 13 | + Questions on decision tree internals and how does it work end-end? 14 | + Model evaluation and selection techniques and questions on that involving confusion matrix etc. 15 | + Questions on K-Fold cross validation and other model validation strategies. 16 | + Model overfitting and Underfitting - How do you know? 17 | + Questions on NLP project that you did. 18 | + Programming question based on sorting (sorting strings in lexographical order) without using any libraries or built-in functions. 19 | + `inplace` and `axis` arguments in pandas apis. 20 | -------------------------------------------------------------------------------- /SymphonyAI/maximumHeightOfMudSegment.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem Statement 3 | A child likes to build mud walls by placing mud between sticks positioned on 4 | a number line. The gap between sticks will be referred to as a cell, and 5 | each cell will contain one segment of wall. The height of mud in a segment 6 | cannot exceed 1 unit above an adjacent stick or mud segment. Given the 7 | placement of a number of sticks and their heights, determine the maximum 8 | height segment of mud that can be built. If no mud segment can be built, 9 | return 0. 10 | 11 | For example, there are n = 3 sticks at stickPositions = [1, 2, 4, 7] with s 12 | tickHeights = [4, 5, 7, 11]. There is no space between the first two sticks, 13 | so there is no cell for mud. Between positions 2 and 4, there is one cell. 14 | Heights of the surrounding sticks are 5 and 7, so the maximum height of mud 15 | is 5 + 1 = 6. Between positions 4 and 7 there are two cells. The heights of 16 | surrounding sticks are 7 and 11. The maximum height mud segment next to the 17 | stick of height 7 is 8. The maximum height mud next to a mud segment of 18 | height 8 and a stick of height 11 is 9. Mud segment heights are 6, 8 and 9, 19 | and the maximum height is 9. In the table below, digits are in the columns 20 | of sticks and M is in the mud segments. 21 | 22 | 7 23 | 7 24 | M7 25 | MM7 26 | 4MM7 27 | M4MM7 28 | 2M4MM7 29 | 12M4MM7 30 | 12M4MM7 31 | 12M4MM7 32 | 12M4MM7 33 | Function Description 34 | Complete the function maxHeight in the editor below. The function must 35 | return an integer, the maximum height mud segment that can be built. 36 | 37 | maxHeight has the following parameter(s): 38 | stickPositions[stickPositions[0],…stickPositions[n-1]]: an array of integers 39 | stickHeights[stickHeights[0],…stickHeights[n-1]]: an array of integers 40 | 41 | Constraints 42 | 1 ≤ n ≤ 105 43 | 1 ≤ stickPositions[i] ≤ 109 (where 0 ≤ i < n) 44 | 1 ≤ stickHeights[i] ≤ 109 (where 0 ≤ i < n) 45 | 46 | Sample Input For Custom Testing 47 | 48 | 3 49 | 1 50 | 3 51 | 7 52 | 3 53 | 4 54 | 3 55 | 3 56 | Sample Output 57 | 58 | 5 59 | Explanation 60 | 61 | M 62 | 1M MMM 63 | 1M3MMM7 64 | 1M3MMM7 65 | 1M3MMM7 66 | Here stickPositions = [1, 3, 7] and stickHeights = [4, 3, 3]. There can be a 67 | segment of height 4 at position 2 supported by sticks of heights 4 and 3. 68 | Between positions 3 and 7, there can be a segment of height 4 at positions 4 69 | and 6. Between them, a segment can be built of height 5 at position 5. 70 | 71 | 72 | """ 73 | 74 | def maxHeight(wallPositions,wallHeights): 75 | n = len(wallPositions) 76 | maxim = 0 77 | for i in range(n-1): 78 | if wallPositions[i] < wallPositions[i+1]-1: 79 | heightDiff = abs(wallHeights[i+1]-wallHeights[i]) 80 | gapLen = wallPositions[i+1]-wallPositions[i]-1 81 | localMax = 0 82 | if gapLen > heightDiff: 83 | low = max(wallHeights[i+1],wallHeights[i]) + 1 84 | remainingGap = gapLen - heightDiff - 1 85 | localMax = low + remainingGap//2 86 | else: 87 | localMax = min(wallHeights[i+1],wallHeights[i]) + gapLen 88 | maxim = max(maxim,localMax) 89 | return maxim 90 | 91 | 92 | if __name__ == '__main__': 93 | wallPositions = [1,2,4,7] 94 | wallHeights = [4,6,8,11] 95 | print (maxHeight(wallPositions=wallPositions,wallHeights=wallHeights)) 96 | wallPositions = [1,3,7] 97 | wallHeights = [4,3,3] 98 | print (maxHeight(wallPositions,wallHeights)) -------------------------------------------------------------------------------- /Tavant-Technologies/README.md: -------------------------------------------------------------------------------- 1 | ## Interview with Senior Technical Architect (Glider discussion): 2 | 1. One Simple Coding question: 3 | - Given a list of candidates (list of names - there can be a name repeating).Number of times the candidate's name is repeating is his votes. So, find the candidate with maximum number of votes and if there is a tie then print the candidates name which is lexicographically smaller. 4 | 2. Variety of questions from big data projects from the CV involving workflow orchestration,Hive,Hadoop 5 | 3. Given a scenario, your knowledge on designing systems is tested aggressively from solutioning approach to implementation. 6 | 4. Difference between external and managed tables in hive 7 | 5. Questions on CI/CD 8 | 6. How would you perform testing (need specifics here!) 9 | 7. How would a design a data ingestion framework that consumes datasets from different data sources (Assume each job of data dump from each source is scheduled at a different time), Design a system that consumes the dump with as minimum latency as possible from different sources and makes it available for different applications? 10 | -------------------------------------------------------------------------------- /Thomson-Reuters/README.md: -------------------------------------------------------------------------------- 1 | # Interview Process - Personal (Machine Learning Engineer) - 2021: 2 | ### First Round - Hackerrank test: 3 | + Given a string, coding question on text preprocessing (cleaning text into corpus) - removing extra characters,removing stopwords, punctuations,text normalization techniques. 4 | + Given a string, coding question on string tokenization, text cleaning techniques (identify numbers,removing words having numbers,identify words with a pattern etc.). 5 | + Multiple choice questions on Machine learning - Model overfitting and underfitting, data leakage, supervised vs unsupervised learning, loss functions, cost minimizations, gradient descent, deep learning etc. 6 | + Multiple choice questions on AWS - AWS lambda, IAM, Cloudformation, sagemaker, billing, S3 etc. (Refer documentation of AWS). 7 | -------------------------------------------------------------------------------- /Thoughtworks/README.md: -------------------------------------------------------------------------------- 1 | Source of Problem Statement for [ScheduleInterviews.py](ScheduleInterviews.py) - [link](https://github.com/YogeshSharma0201/ThoughtWorks-pair-coding-round) 2 | 3 | Original Solution was delivered in C++, But I have developed my own solution in Python. 4 | 5 | FYI - This solution is not a re-implementation or direct translation of code present in [link](https://github.com/YogeshSharma0201/ThoughtWorks-pair-coding-round). 6 | -------------------------------------------------------------------------------- /Twilio/DiskSpaceAnalysis.py: -------------------------------------------------------------------------------- 1 | # Number of Computers: n = 4 2 | # Space = [8,2,4,6] 3 | # x = 2, The segment length 4 | 5 | # The free disk space of computers in each of these segments is [8,2],[2,4] and [4,6] 6 | # The minimum of these three segments are 2, 2 and 4 - [2,2,4] 7 | # Maximum of these is 4 8 | 9 | from typing import List 10 | import math 11 | 12 | def segment(x:int, space:List[int]) -> int: 13 | m,M = x-1,x 14 | segments_generated = [space[i*(M-m):i*(M-m)+M] for i in range(math.ceil((len(space)-m)/(M-m)))] 15 | return max([min(segment) for segment in segments_generated]) 16 | 17 | if __name__ == '__main__': 18 | num_computers = 7 19 | space = [8,2,4,6,10,15,18] 20 | segment_length = 3 21 | 22 | print (segment(x = segment_length, 23 | space=space)) -------------------------------------------------------------------------------- /Twilio/README.md: -------------------------------------------------------------------------------- 1 | ### Hackerrank Test - 2020 2 | 3 | 1. Find the area of largest square that can be found with all 1's present in a binary matrix of 1's and 0's? 4 | 2. Given a sentence, write a word break algorithm that breaks down sentence into number of lines (conditions apply). 5 | 6 | ### Question gleaned from online: [DiskSpaceAnalysis.py](https://github.com/absognety/Interview-Process-Coding-Questions/blob/master/Twilio/DiskSpaceAnalysis.py) 7 | -------------------------------------------------------------------------------- /Uber/README.md: -------------------------------------------------------------------------------- 1 | ## Questions on SQL: 2 | 3 | 1. Let's say there is a table called Completed_Trips. The fields present in the table are `rider_id`,`trip_id` and `trip_date`.Assume there are `X` riders in week 1 and Y riders in immediate following week 2. Retention is defined as ratio of common riders between `X` and `Y` who took atleast 1 trip and number of riders in week 1 who took atleast 1 trip i.e `X` 4 | 5 | **Output:** Plot the retentions for last n weeks -> n is an input here. 6 | **Solution:** 7 | ``` 8 | #n = number of weeks 9 | 10 | n = int(input()) #n = 4 or 5 or ..... 11 | 12 | i = 0 13 | 14 | j = 1 15 | 16 | #Assume df is the parent data frame which is completed_trips 17 | 18 | retentions = [] 19 | 20 | #we can use datetime module to compare dates. 21 | 22 | while (i <= n-1 and j <= n): 23 | 24 | df1 = df[df['trip_date'] < curr_date - 7*i and df['trip_date'] > curr_date - 7*j] 25 | 26 | df2 = df[df['trip_date'] < curr_date - 7*(i+1) and df['trip_date'] > curr_date - 7*(j+1)] 27 | 28 | df1 = df1[df1['trip_id'].notnull()] 29 | 30 | df2 = df2[df2['trip_id'].notnull()] 31 | 32 | count_df1 = set(df1['rider_id'].values) #set gives distinct values 33 | 34 | count_df2 = set(df2['rider_id'].values) 35 | 36 | numerator = len(count_df1 & count_df2) #gives the common riders among all riders 37 | 38 | denominator = len(count_df2) 39 | 40 | retentions.append(numerator/denominator) 41 | 42 | i += 1 43 | 44 | j += 1 45 | 46 | 47 | #If n = 4 48 | #0<=3 and 1<=4 49 | 50 | #1<=3 and 2<=4 51 | 52 | #2<=3 and 3<=4 53 | 54 | #3<=3 and 4<=4 ----------> total 4 times the loop will repeat so we get 4 retentions. 55 | 56 | weeks_var = ["week" + "-" + str(i) for i in range(1,5)] 57 | 58 | final_data = pd.DataFrame({"Week":weeks_var,"Retention":retentions}, 59 | columns = ['Week','Retention']) 60 | 61 | #final_data is ready - we can do line charts, trend charts etc in it. 62 | 63 | ``` 64 | 65 | ## Logical Question (Managerial): 66 | 67 | 2. What are the 3 important metrics that you consider to be important to evaluate people who are reporting to you and why? 68 | + Correctness of Solution Deivered' 69 | + Quality of Solution Delivered 70 | + Adaptability of Solutions Delivered. 71 | You can form your own answers here. 72 | 73 | 74 | ## Process Flow Question (Architecture): 75 | 76 | 3. What are the steps involved in the process doing the FTP for file of any format and putting it in hive location. 77 | + Step-1: Check the location and access 78 | + Step-2: Check the format of file as hive only supports csv/delimited files. 79 | + Step-3: if it is not csv or delimited then try to convert it into structured data set. 80 | + Step-4: Transfer the file using scp protocol binding in python (pysftp) or linux shell. 81 | + Step-5: Once the file is in respective folder, create a hive table with location inserted in table definition with csv serializer. 82 | 83 | 84 | -------------------------------------------------------------------------------- /Uber/getNewArray.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given an array of integers, return a new array such that each element at index i 3 | of the new array is the product of all the numbers in the original array except 4 | the one at i. 5 | 6 | For example, if our input was [1, 2, 3, 4, 5], the expected output would be 7 | [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be 8 | [2, 3, 6]. 9 | """ 10 | 11 | def productOfArray(arr): 12 | prod = 1 13 | for a in arr: 14 | prod = prod * a 15 | return prod 16 | 17 | def newArray(arr): 18 | n = len(arr) 19 | new_arr = [None]*n 20 | for i in range(n): 21 | item = arr.pop(i) 22 | x = productOfArray(arr) 23 | new_arr[i] = x 24 | arr.insert(i,item) 25 | return new_arr 26 | 27 | if __name__ == '__main__': 28 | T = int(input()) 29 | for tcs in range(T): 30 | arr = list(map(int,input().strip().split())) 31 | print (newArray(arr)) -------------------------------------------------------------------------------- /Ushur/README.md: -------------------------------------------------------------------------------- 1 | # Personal Experience: 2 | ## First round - Hackerearth Test 2021 (Data Analytics Engineer): 3 | + Fairly simple coding question (added above) and more multiple choice questions on Machine learning (More than one option, single option etc). 4 | -------------------------------------------------------------------------------- /Ushur/findPairs.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a list of numbers and each number represents a different color of 3 | a sock, Find the number of pairs that can be formed from given list of 4 | socks 5 | 6 | """ 7 | 8 | import collections 9 | def find_pairs(n,socks): 10 | num_pairs = 0 11 | freqs = collections.Counter(socks) 12 | for s,c in freqs.items(): 13 | if c >= 2: 14 | num_pairs += (c//2) 15 | return num_pairs 16 | 17 | 18 | if __name__ == '__main__': 19 | N = 9 20 | socks = [1,2,2,1,3,4,5,2,2] 21 | print (find_pairs(N, socks)) 22 | 23 | N = 10 24 | socks = [1,1,2,1,3,4,5,2,2,0] 25 | print (find_pairs(N, socks)) -------------------------------------------------------------------------------- /VMWare/Convert_Infix_To_Postfix.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import atexit 4 | import io 5 | import sys 6 | # This code is contributed by Nikhil Kumar Singh(nickzuck_007) 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | if __name__ == '__main__': 15 | test_cases = int(input()) 16 | for cases in range(test_cases) : 17 | exp = str(input()) 18 | print(InfixtoPostfix(exp)) 19 | } 20 | ''' This is a function problem.You only need to complete the function given below ''' 21 | #User function Template for python3 22 | ''' 23 | Function Arguments : 24 | @param : exp (given infix expression) 25 | @return : string 26 | ''' 27 | def InfixtoPostfix(exp): 28 | #code here 29 | import string 30 | stack = [] 31 | prec = {'^':4,'*':3,'/':3,'+':2,'-':2,'(':1} 32 | postfixexp = [] 33 | tokens = list(exp) 34 | for token in tokens: 35 | if ((token in string.ascii_lowercase) | (token in "0123456789") | (token in string.ascii_uppercase)): 36 | postfixexp.append(token) 37 | elif token == '(': 38 | stack.append(token) 39 | elif token == ')': 40 | if len(stack)!=0: 41 | topToken = stack.pop() 42 | while topToken != '(': 43 | postfixexp.append(topToken) 44 | topToken = stack.pop() 45 | else: 46 | if len(stack) != 0: 47 | while (len(stack)!=0) and (prec[stack[-1]] >= prec[token]): 48 | postfixexp.append(stack.pop()) 49 | stack.append(token) 50 | while len(stack)!=0: 51 | postfixexp.append(stack.pop()) 52 | return "".join(postfixexp) -------------------------------------------------------------------------------- /VMWare/maxIndexDiffOfArray.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | print(maxIndexDiff(arr,n)) 12 | 13 | 14 | T-=1 15 | if __name__ == "__main__": 16 | main() 17 | } 18 | ''' This is a function problem.You only need to complete the function given below ''' 19 | #User function Template for python3 20 | #Complete this function 21 | def maxIndexDiff(arr, n): 22 | ##Your code here 23 | maxxDiff = 0 24 | for i in range(n): 25 | for j in range(i+1,n): 26 | if arr[i]<=arr[j]: 27 | if maxxDiff < j - i: 28 | maxxDiff = j - i 29 | return maxxDiff -------------------------------------------------------------------------------- /VMWare/mergeKSortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | # Node Class 15 | class Node: 16 | def __init__(self, data): # data -> value stored in node 17 | self.data = data 18 | self.next = None 19 | # Linked List Class 20 | class LinkedList: 21 | def __init__(self): 22 | self.head = None 23 | # creates a new node with given value and appends it at the end of the linked list 24 | def append(self, new_value): 25 | new_node = Node(new_value) 26 | if self.head is None: 27 | self.head = new_node 28 | return 29 | curr_node = self.head 30 | while curr_node.next is not None: 31 | curr_node = curr_node.next 32 | curr_node.next = new_node 33 | # prints the elements of linked list starting with head 34 | def printList(head): 35 | if head is None: 36 | print(' ') 37 | return 38 | curr_node = head 39 | while curr_node: 40 | print(curr_node.data,end=" ") 41 | curr_node=curr_node.next 42 | print(' ') 43 | if __name__ == '__main__': 44 | t=int(input()) 45 | for cases in range(t): 46 | n = int(input()) 47 | a= [] 48 | for i in range(n): 49 | a.append(LinkedList()) 50 | list_info = list(map(int,input().strip().split())) 51 | curr_ind = 0 52 | curr_list_ind = 0 53 | while curr_ind < len(list_info): 54 | nodes= list_info[curr_ind] 55 | curr_ind+=1 56 | for i in range(nodes): 57 | a[curr_list_ind].append(list_info[curr_ind]) 58 | curr_ind += 1 59 | curr_list_ind += 1 60 | heads = [] 61 | for i in range(n): 62 | heads.append(a[i].head) 63 | printList(merge(heads,n)) 64 | 65 | } 66 | ''' This is a function problem.You only need to complete the function given below ''' 67 | #User function Template for python3 68 | ''' 69 | Your task is to merge the given k sorted 70 | linked lists into one list and return 71 | the head of the new formed linked list. 72 | 73 | Function Arguments: array "heads" (containing heads of linked lists), n size of array a. 74 | Return Type: head node.; 75 | { 76 | # Node Class 77 | class Node: 78 | def __init__(self, data): # data -> value stored in node 79 | self.data = data 80 | self.next = None 81 | } 82 | ''' 83 | def merge(heads,n): 84 | #code here 85 | newll = LinkedList() 86 | new_list = [] 87 | for h in heads: 88 | curr_node = h 89 | while curr_node != None: 90 | new_list.append(curr_node.data) 91 | curr_node = curr_node.next 92 | new_list = sorted(new_list) 93 | for ele in new_list: 94 | newll.append(ele) 95 | return newll.head -------------------------------------------------------------------------------- /Vimeo/README.md: -------------------------------------------------------------------------------- 1 | # Senior Data Engineer: Interview Process For Vimeo - 2024: 2 | ## First Round (Format): 3 | + Coding Test with Interviewers present to observe, on Qualified Platform (https://www.qualified.io/). 4 | + SQL section (5 Questions) and Python section (5 Questions), 25 minutes for each section. There is a hard stop when 25 mins is over for each section. 5 | + Python programming section covers questions from Arrays, Linkedlists and Trees and Tree Traversals (Medium Level). 6 | + SQL questions involve Advanced SELECT and JOINS. 7 | 8 | Questions are subject to change with each test, but the format is likely to remain same, but who knows? :blush: :grin: 9 | -------------------------------------------------------------------------------- /Visa/addNode_DoublyLinkedList.py: -------------------------------------------------------------------------------- 1 | { 2 | class Node: 3 | def __init__(self, data): 4 | self.data = data 5 | self.next = None 6 | self.prev = None 7 | class DoublyLinkedList: 8 | def __init__(self): 9 | self.head = None 10 | def append(self, new_data): 11 | new_node = Node(new_data) 12 | new_node.next = None 13 | if self.head is None: 14 | new_node.prev = None 15 | self.head = new_node 16 | return 17 | last = self.head 18 | while(last.next is not None): 19 | last = last.next 20 | last.next = new_node 21 | new_node.prev = last 22 | return 23 | def printList(self, node): 24 | while(node.next is not None): 25 | node = node.next 26 | while node.prev is not None: 27 | node = node.prev 28 | while(node is not None): 29 | print(node.data, end=" ") 30 | node = node.next 31 | print() 32 | 33 | if __name__=='__main__': 34 | t = int(input()) 35 | for i in range(t): 36 | n = int(input()) 37 | arr = map(int, input().strip().split()) 38 | llist = DoublyLinkedList() 39 | for e in arr: 40 | llist.append(e) 41 | pos,data = map(int, input().strip().split()) 42 | addNode(llist.head, pos, data) 43 | llist.printList(llist.head) 44 | # Contributed by: Harshit Sidhwa 45 | 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | # Your task is to complete this function 49 | # function should add a new node after the pth position 50 | # function shouldn't print or return any data 51 | ''' 52 | class Node: 53 | def __init__(self, data): 54 | self.data = data 55 | self.next = None 56 | self.prev = None 57 | ''' 58 | def addNode(head, p, data): 59 | # Code here 60 | temp = Node(data) 61 | if head == None: 62 | head = temp 63 | return 64 | curr_node = head 65 | C = 0 66 | while C <= p: 67 | if C == p: 68 | temp.next = curr_node.next 69 | curr_node.next = temp 70 | if temp.next is not None: 71 | temp.next.prev = temp 72 | temp.prev = curr_node 73 | curr_node = curr_node.next 74 | C += 1 75 | return -------------------------------------------------------------------------------- /Visa/populateList.py: -------------------------------------------------------------------------------- 1 | """ 2 | Populate the list according to following fashion 3 | 4 | Given a list of elements [a0, a1, a2, ......, an-1] of length n 5 | 6 | Return a list of length n such that it has the following traversal 7 | 8 | Input: [a0, a1, a2, ......, an-1] 9 | Output: [a0, an-1, a1, an-2, a2, an-3,........] 10 | """ 11 | 12 | def solution(numbers): 13 | size_of_arr = len(numbers) 14 | result = list() 15 | for ind in range(size_of_arr): 16 | if len(result) == size_of_arr: 17 | break 18 | result.append(numbers[ind]) 19 | if (ind != size_of_arr - ind - 1): 20 | result.append(numbers[size_of_arr - ind - 1]) 21 | return result 22 | 23 | if __name__ == '__main__': 24 | input1 = [2, 5, -10, -4, 0, 8] 25 | print (solution(input1)) 26 | 27 | input2 = [1, 20, 3, 8, 5] 28 | print (solution(input2)) 29 | 30 | input3 = [10, -1, 0, 8, 9, -1, 5, -5, 6, 9, 20, 10] 31 | print (solution(input3)) -------------------------------------------------------------------------------- /Visa/removeDuplicatesSortedLinkedList.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | #Contributed by : Nagendra Jha 4 | import atexit 5 | import io 6 | import sys 7 | _INPUT_LINES = sys.stdin.read().splitlines() 8 | input = iter(_INPUT_LINES).__next__ 9 | _OUTPUT_BUFFER = io.StringIO() 10 | sys.stdout = _OUTPUT_BUFFER 11 | @atexit.register 12 | def write(): 13 | sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) 14 | 15 | # Node Class 16 | class Node: 17 | def __init__(self, data): # data -> value stored in node 18 | self.data = data 19 | self.next = None 20 | # Linked List Class 21 | class LinkedList: 22 | def __init__(self): 23 | self.head = None 24 | # creates a new node with given value and appends it at the end of the linked list 25 | def append(self, new_value): 26 | new_node = Node(new_value) 27 | if self.head is None: 28 | self.head = new_node 29 | return 30 | curr_node = self.head 31 | while curr_node.next is not None: 32 | curr_node = curr_node.next 33 | curr_node.next = new_node 34 | # prints the elements of linked list starting with head 35 | def printList(self): 36 | if self.head is None: 37 | print(' ') 38 | return 39 | curr_node = self.head 40 | while curr_node: 41 | print(curr_node.data,end=" ") 42 | curr_node=curr_node.next 43 | print(' ') 44 | 45 | if __name__ == '__main__': 46 | t=int(input()) 47 | for cases in range(t): 48 | n = int(input()) 49 | a = LinkedList() # create a new linked list 'a'. 50 | nodes = list(map(int, input().strip().split())) 51 | for x in nodes: 52 | a.append(x) 53 | removeDuplicates(a.head) 54 | a.printList() 55 | } 56 | ''' This is a function problem.You only need to complete the function given below ''' 57 | #User function Template for python3 58 | ''' 59 | Your task is to remove duplicates from given 60 | sorted linked list. 61 | 62 | Function Arguments: head (head of the given linked list) 63 | Return Type: none, just remove the duplicates from the list. 64 | { 65 | # Node Class 66 | class Node: 67 | def __init__(self, data): # data -> value stored in node 68 | self.data = data 69 | self.next = None 70 | } 71 | ''' 72 | def removeDuplicates(head): 73 | #code here 74 | global a 75 | curr_node = head 76 | duplicateTracker = [] 77 | while curr_node != None: 78 | if curr_node.data not in duplicateTracker: 79 | duplicateTracker.append(curr_node.data) 80 | curr_node = curr_node.next 81 | a = LinkedList() 82 | for x in duplicateTracker: 83 | a.append(x) -------------------------------------------------------------------------------- /Walmart/GroupAnagrams.py: -------------------------------------------------------------------------------- 1 | ## Data Engineering Interview at Walmart 2 | 3 | # Find the words from the given list and group them with the words which are 4 | # formed by different arrangements of the same letters(anagram) 5 | 6 | # Input = ['mat','tam','cute','beat','eatb','teab','ateb'] 7 | # Output = [[“mat”, “tam”],[“cute”],[“beat”,”eatb”,”teab”,”ateb”]] 8 | 9 | # Input = ['lump', 'eat', 'me', 'tea', 'em', 'plum'] 10 | 11 | # Without using Advanced Data structures and libraries 12 | from typing import List,Tuple 13 | from collections import defaultdict 14 | def group_anagrams(words:List[str]) -> List[Tuple[str]]: 15 | groups = [] 16 | for i in range(len(words)): 17 | collect_groups=[] 18 | for j in range(i+1,len(words)): 19 | if sorted(words[i]) == sorted(words[j]): 20 | if words[i] != words[j]: 21 | collect_groups.append(words[i]) 22 | collect_groups.append(words[j]) 23 | else: 24 | continue 25 | if len(collect_groups) > 0: 26 | groups.append(tuple(set(collect_groups))) 27 | else: 28 | groups.append((words[i],)) 29 | result = [] 30 | for i in range(len(groups)): 31 | checker = [] 32 | for j in range(len(groups)): 33 | if i != j: 34 | if set(groups[i]).issubset(set(groups[j])): 35 | checker.append(1) 36 | else: 37 | checker.append(0) 38 | else: 39 | continue 40 | if (len(set(checker)) == 1) and (0 in checker): 41 | result.append(groups[i]) 42 | return result 43 | 44 | def group_anagrams_1(words:List[str]) -> List[Tuple[str]]: 45 | temp = defaultdict(list) 46 | for ele in words: 47 | temp[str(sorted(ele))].append(ele) 48 | print (temp) 49 | return list(temp.values()) 50 | 51 | if __name__ == '__main__': 52 | # words = list(input().strip().split(",")) 53 | # print (group_anagrams(words=words)) 54 | print (group_anagrams_1(words=['lump', 'eat', 'me', 'tea', 'em', 'plum'])) 55 | print (group_anagrams(words=['mat','tam','cute','beat','eatb','teab','ateb'])) 56 | print (group_anagrams_1(words=['mat','tam','cute','beat','eatb','teab','ateb'])) -------------------------------------------------------------------------------- /Walmart/minimumCoins.py: -------------------------------------------------------------------------------- 1 | # Given a value V, if we want to make a change for V cents, and we have a finite supply of 2 | # each of C = { C1, C2, .., Cm} valued coins, what is the minimum number of coins to make the change? 3 | # If it’s not possible to make a change, print -1. 4 | 5 | # Examples: 6 | # finite supply is just coin values provided in the list, cannot use more than those 7 | 8 | # Input: coins[] = {25, 10, 5}, V = 30 9 | # Output: Minimum 2 coins required We can use one coin of 25 cents and one of 5 cents 10 | 11 | # Input: coins[] = {9, 6, 5, 1}, V = 11 12 | # Output: Minimum 2 coins required We can use one coin of 6 cents and 1 coin of 5 cents 13 | 14 | from typing import List 15 | import itertools 16 | def minCoins(coins:List[int],value:int) -> int: 17 | if value == 0: 18 | return 0 19 | maxlength = len(coins) 20 | for l in range(1,maxlength,1): 21 | combinations = list(itertools.combinations(coins,l)) 22 | for c in combinations: 23 | if sum(c)==value: 24 | return f"Minimum {l} coins required, we can use coins of {(','.join([str(i) for i in c]))} cents" 25 | else: 26 | continue 27 | return -1 28 | 29 | 30 | if __name__ == '__main__': 31 | coins = list(map(int,input().strip().split(' '))) 32 | value = int(input()) 33 | print (minCoins(coins,value)) -------------------------------------------------------------------------------- /Walmart/minimumCoinsRecursive.py: -------------------------------------------------------------------------------- 1 | # Given a value V, if we want to make a change for V cents, and we have an infinite supply of 2 | # each of C = { C1, C2, .., Cm} valued coins, what is the minimum number of coins to make the change? 3 | # If it’s not possible to make a change, print -1. 4 | 5 | # Examples: 6 | 7 | # Input: coins[] = {25, 10, 5}, V = 30 8 | # Output: Minimum 2 coins required We can use one coin of 25 cents and one of 5 cents 9 | 10 | # Input: coins[] = {9, 6, 5, 1}, V = 11 11 | # Output: Minimum 2 coins required We can use one coin of 6 cents and 1 coin of 5 cents 12 | 13 | from typing import List 14 | import sys 15 | def minimumCoinsRecursive(coins:List[int],value:int) -> int: 16 | if value == 0: 17 | return 0 18 | coins_l = len(coins) 19 | res = sys.maxsize 20 | for i in range(coins_l): 21 | if coins[i] <= value: 22 | sub_res = minimumCoinsRecursive(coins,value-coins[i]) 23 | if ((sub_res != sys.maxsize) & (sub_res + 1 < res)): 24 | res = sub_res + 1 25 | return res 26 | 27 | if __name__ == '__main__': 28 | coins = list(map(int,input().strip().split(' '))) 29 | print (coins) 30 | value = int(input()) 31 | print (value) 32 | print (minimumCoinsRecursive(coins,value)) -------------------------------------------------------------------------------- /Yahoo/ThreeWayPartition.py: -------------------------------------------------------------------------------- 1 | { 2 | # Driver Program 3 | from collections import Counter 4 | if __name__=='__main__': 5 | t = int(input()) 6 | for i in range(t): 7 | n = int(input()) 8 | arr = list(map(int, input().strip().split())) 9 | brr = Counter(arr) 10 | a,b = list(map(int, input().strip().split())) 11 | res = threeWayPartition(arr, n, a, b) 12 | k1 = k2 = k3 = 0 13 | for e in arr: 14 | if e > a: 15 | k3+=1 16 | elif e<=a and e>=b: 17 | k2+=1 18 | elif e=b: 26 | m2+=1 27 | for e in range(k1+k2, k1+k2+k3): 28 | if res[e]>=a: 29 | m3+=1 30 | flag = False 31 | if k1==m1 and k2==m2 and k3==m3: 32 | flag = True 33 | for e in range(len(res)): 34 | brr[res[e]]-=1 35 | for e in range(len(res)): 36 | if brr[res[e]]!=0: 37 | flag = False 38 | if flag: 39 | print(1) 40 | else: 41 | print(0) 42 | # Contributed by: Harshit Sidhwa 43 | } 44 | ''' This is a function problem.You only need to complete the function given below ''' 45 | # Your task is to complete this function 46 | # function should a list containing the required order of the elements 47 | def threeWayPartition(arr, n, a, b): 48 | # Code here 49 | lessa = [] 50 | atob = [] 51 | greatb = [] 52 | for i in range(n): 53 | if arr[i] < a: 54 | lessa.append(arr[i]) 55 | elif arr[i] >= a and arr[i] <= b: 56 | atob.append(arr[i]) 57 | elif arr[i] > b: 58 | greatb.append(arr[i]) 59 | farr = lessa + atob + greatb 60 | return farr -------------------------------------------------------------------------------- /ZSAssociates/CrossSequence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given an array A, Integer K 3 | 4 | Find the Kth Smallest element of array which is generated from 5 | calculating the absolute differences of the cartesian product of the 6 | array elements 7 | 8 | 9 | Example: 10 | A = [4,2,1] 11 | K = 5 12 | N = size(A) = 3 13 | 14 | S = [|4-4|,|4-2|,|4-1|,|2-4|,|2-2|,|2-1|,|1-4|,|1-2|,|1-1|] 15 | S = [0,2,3,2,0,1,3,1,0] 16 | S = [0,0,0,1,1,2,2,3,3,3] (sorted) 17 | 5th Smallest element (assuming 1-indexing) is 4 18 | """ 19 | 20 | import itertools 21 | def solve(N,A,K): 22 | cartesian_product = itertools.product(A,A) 23 | abs_diffs = [abs(i-j) for i,j in cartesian_product] 24 | return sorted(abs_diffs)[K-1] 25 | 26 | if __name__ == '__main__': 27 | A = [4,2,1] 28 | N = len(A) 29 | K = 5 30 | print (solve(N,A,K)) -------------------------------------------------------------------------------- /ZSAssociates/OutputOfProgram.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from pyspark import SparkContext 3 | from pyspark.sql.functions import col,struct,pandas_udf,PandasUDFType 4 | from pyspark.sql import SQLContext 5 | sc = SparkContext("local","test") 6 | x = pd.Series([1,2,3]) 7 | pdf = pd.DataFrame([1,2,3],columns = ['x']) 8 | df = SQLContext(sc).createDataFrame(pdf) 9 | 10 | @pandas_udf("long",PandasUDFType.SCALAR_ITER) 11 | def plus_one(batch_iter): 12 | for x in batch_iter: 13 | yield x + 1 14 | 15 | @pandas_udf("long",PandasUDFType.SCALAR_ITER) 16 | def multiply_two_cols(batch_iter): 17 | for a,b in batch_iter: 18 | yield a * b 19 | 20 | df.select(multiply_two_cols(col("x"),col("x"))).show() -------------------------------------------------------------------------------- /ZSAssociates/OutputOfProgram2.py: -------------------------------------------------------------------------------- 1 | def MainProgram(iterable, x): 2 | sample = tuple(iterable) 3 | n = len(sample) 4 | if not n and x: 5 | return 6 | indices = [1] * x 7 | yield tuple(sample[i] for i in indices) 8 | while True: 9 | for i in reversed(range(x)): 10 | if indices[i] != n-1: 11 | break 12 | else: 13 | return 14 | indices[i:] = [indices[i] + 1] * (x-i) 15 | yield tuple(sample[i] for i in indices) 16 | 17 | a = MainProgram('PYTHON', 3) 18 | print (next(a)) 19 | 20 | def MainProg(f): 21 | m = {} 22 | def InnerProg(num): 23 | if num not in m: 24 | m[num] = f(num) 25 | return m[num] 26 | return InnerProg 27 | 28 | @MainProg 29 | def Call(num): 30 | if num == 0: 31 | return 1 32 | else: 33 | return num**2*Call(num-1) 34 | 35 | print (Call(3)) -------------------------------------------------------------------------------- /Zoho/merge2SortedLinkedLists.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | # Node Class 4 | class Node: 5 | def __init__(self, data): # data -> value stored in node 6 | self.data = data 7 | self.next = None 8 | # Linked List Class 9 | class LinkedList: 10 | def __init__(self): 11 | self.head = None 12 | # creates a new node with given value and appends it at the end of the linked list 13 | def append(self, new_value): 14 | new_node = Node(new_value) 15 | if self.head is None: 16 | self.head = new_node 17 | return 18 | curr_node = self.head 19 | while curr_node.next is not None: 20 | curr_node = curr_node.next 21 | curr_node.next = new_node 22 | # prints the elements of linked list starting with head 23 | def printList(self): 24 | if self.head is None: 25 | print(' ') 26 | return 27 | curr_node = self.head 28 | while curr_node: 29 | print(curr_node.data,end=" ") 30 | curr_node=curr_node.next 31 | print(' ') 32 | if __name__ == '__main__': 33 | t=int(input()) 34 | for cases in range(t): 35 | n,m = map(int, input().strip().split()) 36 | a = LinkedList() # create a new linked list 'a'. 37 | b = LinkedList() # create a new linked list 'b'. 38 | nodes_a = list(map(int, input().strip().split())) 39 | nodes_b = list(map(int, input().strip().split())) 40 | for x in nodes_a: 41 | a.append(x) 42 | for x in nodes_b: 43 | b.append(x) 44 | a.head = merge(a.head,b.head) 45 | a.printList() 46 | } 47 | ''' This is a function problem.You only need to complete the function given below ''' 48 | #User function Template for python3 49 | ''' 50 | Function to merge two sorted lists in one 51 | using constant space. 52 | 53 | Function Arguments: head_a and head_b (head reference of both the sorted lists) 54 | Return Type: head of the obtained list after merger. 55 | { 56 | # Node Class 57 | class Node: 58 | def __init__(self, data): # data -> value stored in node 59 | self.data = data 60 | self.next = None 61 | } 62 | Contributed By: Nagendra Jha 63 | ''' 64 | def merge(head_a,head_b): 65 | #code here 66 | global a 67 | elements = [] 68 | curr_node = head_a 69 | while curr_node != None: 70 | elements.append(curr_node.data) 71 | curr_node = curr_node.next 72 | curr_node = head_b 73 | while curr_node != None: 74 | elements.append(curr_node.data) 75 | curr_node = curr_node.next 76 | elements = sorted(elements) 77 | a = LinkedList() 78 | for i in elements: 79 | a.append(i) 80 | return a.head -------------------------------------------------------------------------------- /Zoho/rearrangeArrayAlternately.py: -------------------------------------------------------------------------------- 1 | { 2 | #Initial Template for Python 3 3 | import math 4 | def main(): 5 | T=int(input()) 6 | while(T>0): 7 | 8 | n=int(input()) 9 | 10 | arr=[int(x) for x in input().strip().split()] 11 | 12 | arre = rearrange(arr,n) 13 | 14 | for i in arre: 15 | print(i,end=" ") 16 | 17 | print() 18 | 19 | T-=1 20 | if __name__ == "__main__": 21 | main() 22 | } 23 | ''' This is a function problem.You only need to complete the function given below ''' 24 | #User function Template for python3 25 | ##Complete this function 26 | def rearrange(arr, n): 27 | ##Your code here 28 | if n%2 == 0: 29 | for i in range(n//2): 30 | arr.append(arr[n-1-i]) 31 | arr.append(arr[i]) 32 | else: 33 | for i in range(n//2): 34 | arr.append(arr[n-1-i]) 35 | arr.append(arr[i]) 36 | arr.append(arr[math.floor(n/2)]) 37 | arr[:] = arr[n:] 38 | return arr -------------------------------------------------------------------------------- /Zycus/README.md: -------------------------------------------------------------------------------- 1 | # Personal Experience (Interview Process for AI/Machine Learning Engineer - 2020): 2 | ### First screening round: 3 | + Interview with the Director of AI teams: 4 | 5 | Case study: Dataset is as below: 6 | 7 | | itemId | item_name | item_description | manufacturer_name | supplier_name | target_variable(home/workplace) | 8 | |--------|-----------|-----------------------|-------------------|---------------|---------------------------------| 9 | | 1000 | monitor | ram: 32gb,2.8 GHZ,HDD | HP | senty pvt ltd | workplace | 10 | | 1001 | | | | | | 11 | | 1003 | | | | | | 12 | 13 | Given only sample size of 10 of above schema (with target variable assigned), training dataset(without target_variable assigned) size is 100, how would you avoid the effort of manual tagging of target variable to training data? 14 | #### Follow up questions: 15 | + How would you select the variables? 16 | + How would u use the opentext column `item_description`? 17 | 18 | The round is for just 10 minutes, and I didn't get selected. 19 | 20 | #### My solution: 21 | + k-NN/decision tree algorithm for dependent variable tagging (even associaton rule mining algorithms that include apriori and eclat). 22 | + initial selection of variables is based on domain knowledge as number of variables is very less here. 23 | + preprocess the text column `item_description` maybe do text summarization of the full text and extract keywords using bi-grams and collocations and use that tag in further processing. 24 | 25 | 26 | ## Use https://www.tablesgenerator.com/markdown_tables# for quick tables generation in markdown, It's elegant and simple. 27 | -------------------------------------------------------------------------------- /cimpress/README.md: -------------------------------------------------------------------------------- 1 | Interview Process for Data Engineer - 2021 (Personal Experience): 2 | ================================================================= 3 | ### 1. First Round - Introductory Round: 4 | + Introduction to yourself,About the company. 5 | + Project experience, Tech stacks you are comfortable with, basic programming questions. 6 | + Relevance of your background to the role. 7 | + Interview process detailing and other questions if you may have or interviewer has. 8 | 9 | ### 2. Online Coding Test on Codility: 10 | + 1 question on SQL and 1 question on programming. 11 | + Programming question - Say a string composed of only letters a and b, numbers of ways to split it into 3 substrings such that all 3 substrings have same number of character 'a's. 12 | + SQL question: Please find the question below - 13 | 14 | ![image](https://user-images.githubusercontent.com/25507554/120599363-0a640480-c465-11eb-8b40-bb91a3c8bc3c.png) 15 | 16 | ### 3. Coding Round (Programming test - Data transformations using Apache Spark Live): 17 | + Given 2 data questions - Transform data using Apache spark transformations live, Execute them and present the results - environment for execution of spark programs is provided. 18 | 19 | ### 4. Design Round: 20 | + Document is provided which describes the problem statement and bottlenecks in existing architecture and what the requirement is - Design a scalable Machine learning system that automates the e2e ML workflows and helps analysts and stakeholders in their seamless outputs consumption - Architectural choices, Technology stack that you choose need to be explained clearly and reason behind that choice - would be an addition if the alternative approaches are also explained. 21 | 22 | ### 5. Problem Solving Round: 23 | + This round is not a technical interview but tests on the problem solving skills of yours - A real world situation with some helpers are given, come up with the steps to mitigate the problem and measures taken to solve that problem. 24 | 25 | ### 6. Awesomeness interview: 26 | + Discussions and questions about working with a team and challenges that are faced - questions on how you handled that in past. 27 | 28 | ### 7. Behavioral Interview: 29 | + Working under a stressful situation. 30 | + How is the conflict with a co-worker resolved? 31 | + How do you keep yourself updated and enthusiastic about latest tech trends? and other questions. 32 | --------------------------------------------------------------------------------