master da7b50a1b9b8 cached
156 files
243.8 KB
72.0k tokens
320 symbols
1 requests
Download .txt
Showing preview only (279K chars total). Download the full file or copy to clipboard to get everything.
Repository: absognety/Interview-Process-Coding-Questions
Branch: master
Commit: da7b50a1b9b8
Files: 156
Total size: 243.8 KB

Directory structure:
gitextract_je5aerut/

├── .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
├── 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
├── DATFreightAnalytics/
│   └── 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
│   └── problem02/
│       └── countMe.py
├── 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
├── Nielsen/
│   └── README.md
├── 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

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/


================================================
FILE: 6sense/README.md
================================================
# Hackerrank Test (Personal Experience):  


================================================
FILE: 6sense/findWordInGrid.py
================================================
"""
Refer below link for the question:
    https://www.geeksforgeeks.org/search-a-word-in-a-2d-grid-of-characters/

Solution:
    Algorithm for this is already present, but expected solution should 
    have lowest time complexity (the algorithm should only traverse once unlike the 
    solution above which traverses whole matrix for each word given)

Enhancement: 
    if the word is not present in the grid, print word along with row 
    and col as (-1,-1) like word,-1,-1

Hint: 
    Use DP approach

Solution that I have gone with is below:

"""

# Enter your code here. Read input from STDIN. Print output to STDOUT
import sys
class word_seek: 
      
    def __init__(self): 
        self.R = None
        self.C = None
        self.dir = [[-1, 0], [1, 0], [1, 1],  
                    [1, -1], [-1, -1], [-1, 1], 
                    [0, 1], [0, -1]] 
    def search_grid(self, grid, row, col, word): 
        if grid[row][col] != word[0]: 
            return False
        for x, y in self.dir: 
            rd, cd = row + x, col + y 
            flag = True
            for k in range(1, len(word)): 
                if (0 <= rd <self.R and 
                    0 <= cd < self.C and 
                    word[k] == grid[rd][cd]):  
                    rd += x 
                    cd += y 
                else: 
                    flag = False
                    break       
            if flag: 
                return True
        return False  
    def patternSearch(self, grid, word): 
        self.R = len(grid) 
        self.C = len(grid[0])
        tracker = []
        for row in range(self.R): 
            for col in range(self.C): 
                if self.search_grid(grid, row, col, word): 
                    tracker.append((word,row,col))
                else:
                    tracker.append((word,-1,-1))
        if len(set(tracker)) > 1:
            tracker = sorted(tracker,key=lambda x: x[1],reverse=True)
            print (tracker[0][0],tracker[0][1],tracker[0][2])
            return
        else:
            assert (tracker[0][1] == -1) and (tracker[0][2] == -1),"failed"
            print (tracker[0][0],tracker[0][1],tracker[0][2])
            return

if __name__ == '__main__':
    grid = sys.stdin.readlines()
    grid = [i.strip() for i in grid]
    ind = grid.index('')
    #grid = grid[:(ind)]
    #finders = grid[(ind+1):]
    #print (grid)
    #print (finders)
    wordSeek = word_seek()
    for w in grid[(ind+1):]:
        wordSeek.patternSearch(grid[:(ind)],w)

================================================
FILE: Accenture/README.md
================================================
# Interview Process - Data Engineer - Round 1 (Skills Interview):  
+ Can a python class have 2 __init__ methods?  
+ Questions on class methods (staticmethods and classmethods).  
+ Difference between method and function?  
+ what are the ways in spark when writing data to storage to reduce or increase number of part files?  
+ Difference between repartition and coalesce in Spark.  
+ What is shuffle in spark?  
+ can data be stored without indexes?  
+ Object versioning in AWS S3?  
+ Access contol policies in AWS S3 when creating a bucket?  
+ Indexing in mongodb?  
+ Given a small table with field names, write a sql query or spark code to get the required aggregation? refer Window functionality and ranking.  
+ Differences between client mode and cluster mode (Spark execution) (https://stackoverflow.com/questions/37027732/apache-spark-differences-between-client-and-cluster-deploy-modes).  
+ Machine learning - classification model - questions on model selection, model evaluation?  
+ deploy a flask app in azure - what is the approach?  
+ Questions on azure fundamentals?  
+ what are the configurations for spark app when spark-submit is done?  


================================================
FILE: Accolite/binaryArraySort.py
================================================
{
#Initial Template for Python 3
import math
def main():
        T=int(input())
        while(T>0):
            N=int(input())
            A=list(map(int,input().split()))
            
            binSort(A,N)
            
            for i in A:
                print(i,end=" ")
            print()
            
            T-=1
if __name__ == "__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
##Complete this function
def binSort(arr, n): 
    #Your code here
    
    
    '''
    No need to print the array
    '''
    c0 = arr.count(0)
    c1 = arr.count(1)
    for i in range(c0):
        arr[i] = 0
    for i in range(c0,c0+c1):
        arr[i] = 1

================================================
FILE: Accolite/merge2SortedLinkedLists.py
================================================
{
#Initial Template for Python 3
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n,m = map(int, input().strip().split())
        a = LinkedList() # create a new linked list 'a'.
        b = LinkedList() # create a new linked list 'b'.
        nodes_a = list(map(int, input().strip().split()))
        nodes_b = list(map(int, input().strip().split()))
        for x in nodes_a:
            a.append(x)
        for x in nodes_b:
            b.append(x)
        a.head = merge(a.head,b.head)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Function to merge two sorted lists in one
	using constant space.
	
	Function Arguments: head_a and head_b (head reference of both the sorted lists)
	Return Type: head of the obtained list after merger.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
	Contributed By: Nagendra Jha
'''
def merge(head_a,head_b):
    #code here
    global a
    elements = []
    curr_node = head_a
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    curr_node = head_b
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    elements = sorted(elements)
    a = LinkedList()
    for i in elements:
        a.append(i)
    return a.head

================================================
FILE: Accolite/rotateLinkedListByKelements.py
================================================
{
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
class LinkedList:
    def __init__(self):
        self.head = None
    def push(self, new_data):
        new_node = Node(new_data)
        new_node.next = self.head
        self.head = new_node
    def printList(self):
        temp = self.head
        while(temp):
            print(temp.data, end=" ")
            # arr.append(str(temp.data))
            temp = temp.next
        print("")
if __name__ == '__main__':
    start = LinkedList()
    t = int(input())
    while(t > 0):
        llist = LinkedList()
        n = int(input())
        values = list(map(int, input().strip().split()))
        for i in reversed(values):
            llist.push(i)
        k = int(input())
        new_head = rotateList(llist.head, k)
        llist.head = new_head
        llist.printList()
        t -= 1
# Contributed by: Harshit Sidhwa

}
''' This is a function problem.You only need to complete the function given below '''
# Your task is to complete this function
'''
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
'''
# This function should rotate list counter-
# clockwise by k and return new head (if changed) 
def rotateList(head, k):
    # code here
    global llist
    llist = LinkedList()
    C = 0
    curr_node = head
    part1 = []
    part2 = []
    while curr_node != None:
        if C <= k-1:
            part1.append(curr_node.data)
        elif C > k-1:
            part2.append(curr_node.data)
        C += 1
        curr_node = curr_node.next
    total = reversed(part2 + part1)
    for i in total:
        llist.push(i)
    return llist.head

================================================
FILE: Adobe/QuickSort.py
================================================
{
#Initial Template for Python 3
if __name__ == "__main__":
    t=int(input())
    for i in range(t):
        n=int(input())
        arr=list(map(int,input().split()))
        quickSort(arr,0,n-1)
        for i in range(n):
            print(arr[i],end=" ")
        print()

}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
def quickSort(arr,low,high):
    if low < high:
 
        # pi is partitioning index, arr[p] is now
        # at right place
        pi = partition(arr,low,high)
 
        # Separately sort elements before
        # partition and after partition
        quickSort(arr, low, pi-1)
        quickSort(arr, pi+1, high)
        
def partition(arr,low,high):
    #add code here
    tmp = 0
    pivot = arr[high]
    i = low - 1
    for j in range(low,high):
        if arr[j] <= pivot:
            i += 1
            tmp = arr[i]
            arr[i] = arr[j]
            arr[j] = tmp
    tmp = arr[i+1]
    arr[i+1] = arr[high]
    arr[high] = tmp
    return i+1

================================================
FILE: Adobe/WinnerOfElection.py
================================================
{
#Initial Template for Python 3
    
def main():
    T=int(input())
    while(T>0):
        
        n=int(input())
        arr=input().strip().split()
        
        winner(arr,n)
        print()
        
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function
def winner(arr,n):
    #Your code here
    import collections
    votes = collections.Counter(arr)
    maxVotes = max(votes.values())
    if len(set(votes.values())) != len(votes.values()):
        maxVoteNames = []
        for k,v in votes.items():
            if v == maxVotes:
                maxVoteNames.append(k)
        print (min(maxVoteNames),maxVotes,end="")
    else:
        for k,v in votes.items():
            if v == maxVotes:
                print (k,maxVotes,end="")
                return

================================================
FILE: Adobe/checkIfStringsAreRotations.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for i in range(t):
        s1=str(input())
        s2=str(input())
        if(areRotations(s1,s2)):
            print(1)
        else:
            print(0)
    
        
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is tocheck if the given two strings
	are rotations of each other.
	Function Arguments: s1 and s2 (given strings)
	Return Type:boolean
'''
def areRotations(s1,s2):
    if (len(s1) == 1 or len(s2) == 1) & (s1 != s2):
        return False
    #code here
    if (len(s1) == len(s2)) & (set(s1)==set(s2)) & (s2 in s1+s2) & (s1 in s1+s2):
        return True
    else:
        return False

================================================
FILE: Adobe/countOfInversionsArray.py
================================================
# GeeksForGeeks Code - Copied#
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for tt in range(t):
        n = int(input())
        a = list(map(int, input().strip().split()))
        print(Inversion_Count(a,n))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to return total number of inversions
	present in the array.
	
	Function Arguments: array a and size n
	Return Type: Integer 
'''
def Inversion_Count(arr,n):
    if a == sorted(a):
        return 0
    temp_arr = [0]*n
    return mergesort(arr,temp_arr,0,n-1)
    
def mergesort(arr,temp_arr,left,right):
    inv_count = 0
    if left < right:
        mid = (left + right)//2
        inv_count = mergesort(arr,temp_arr,left,mid)
        inv_count += mergesort(arr,temp_arr,mid+1,right)
        inv_count += merge(arr,temp_arr,left,mid,right)
    return inv_count
    
def merge(arr,temp_arr,left, mid, right): 
    # Merge the temp arrays back into arr[l..r] 
    i = left     # Initial index of first subarray 
    j = mid+1     # Initial index of second subarray 
    k = left     # Initial index of merged subarray 
    invcount = 0
    while i <= mid and j <= right: 
        if arr[i] <= arr[j]:
            temp_arr[k] = arr[i] 
            i += 1
        else: 
            temp_arr[k] = arr[j]
            invcount += (mid - i + 1)
            j += 1
        k += 1
    # Copy the remaining elements of L[], if there 
    # are any 
    while i <= mid: 
        temp_arr[k] = arr[i] 
        i += 1
        k += 1
    # Copy the remaining elements of R[], if there 
    # are any 
    while j <= right: 
        temp_arr[k] = arr[j] 
        j += 1
        k += 1
        
    for lr in range(left, right + 1): 
        arr[lr] = temp_arr[lr] 
    return invcount


================================================
FILE: Adobe/parenthesisChecker.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
#Contributed by : Nagendra Jha
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    test_cases = int(input())
    for cases in range(test_cases) :
        #n = int(input())
        #n,k = map(int,imput().strip().split())
        #a = list(map(int,input().strip().split()))
        s = str(input())
        if ispar(s):
            print("balanced")
        else:
            print("not balanced")
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
Function Arguments :
		@param  : s (given string containing parenthesis) 
		@return : boolean True or False
'''

def isMatchingPair(c1,c2):
    if (c1=='(') & (c2==')'):
        return True
    elif (c1=='{') & (c2=='}'):
        return True
    elif (c1=='[') & (c2==']'):
        return True
    else:
        return False
        
def ispar(s):
    # code here
    import queue
    stack = queue.LifoQueue()
    
    for i in range(len(s)):
        if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')):
            stack.put(s[i])
        if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')):
            if stack.empty():
                return False
            elif not isMatchingPair(stack.get(),s[i]):
                return False
        
    if stack.empty():
        return True
    else:
        return False

================================================
FILE: Amazon/DataEngineering/README.md
================================================
# Data Engineering Assessment (As of Oct 2024):
+ Assessment redirected to Hackerank from Amazon Jobs profile configuration.  
+ Assessment with a maximum duration of 120 mins.  
+ Multiple Choice Questions on Very basic SQL (Joins, MySQL syntax, Error recognition etc..). Around 20 MCQs.
+ 3 SQL coding questions, Easy, Medium and Hard [Simple Joins to writing subqueries to ranking + CTEs + Computing Aggregate metrics + subqueries]


================================================
FILE: Amazon/Delete_Node_Without_HeadPointer.py
================================================
class Node(object):
    def __init__(self,dataVal,nextNode=None):
        self.data = dataVal
        self.next = nextNode
        
    def getData(self):
        return (self.data)
    
    def setData(self,val):
        self.data = val
        
    def getNextNode(self):
        return (self.next)
    
    def setNextNode(self,val):
        self.next = val
        
class LinkedList(object):
    def __init__(self,head=None):
        self.head = head
        self.size = 0
        
    def getSize(self):
        return (self.size)
    
    def addNode(self,data):
        newNode = Node(data)
        newNode.setNextNode(self.head)
        self.head = newNode
        self.size += 1
        return True
    
    def printNode(self):
        curr = self.head
        while curr:
            print (curr.data)
            curr = curr.getNextNode()
        
    def deleteNode(self,value):
        
        prev = None
        curr = self.head
        while curr:
            if curr.data == value:
                if prev:
                    prev.setNextNode(curr.getNextNode())
                else:
                    self.head = curr.getNextNode()
                self.size -= 1
                return True
                    
            prev = curr
            curr = curr.getNextNode()
            
        return False
        
            
myList = LinkedList()
print (myList.getSize())
print ("______*Inserting*_______")

myList.addNode(5)
myList.addNode(10)
myList.addNode(15)
myList.addNode(20)
myList.addNode(25)

print ("printing")
myList.printNode()

print ("Deleting")
myList.deleteNode(10)
myList.deleteNode(20)
myList.deleteNode(5)

myList.addNode(90)
myList.addNode(2000)
print (myList.getSize())
myList.printNode()

================================================
FILE: Amazon/EquilibriumPointFirstOccurWhere.py
================================================
{
# Initial Template for Python 3
import math
def main():
    T = int(input())
    while(T > 0):
        N = int(input())
        A = [int(x) for x in input().strip().split()]
        print(equilibriumPoint(A, N))
        T -= 1
if __name__ == "__main__":
    main()

}
''' This is a function problem.You only need to complete the function given below '''
# User function Template for python3
# Complete this function
def equilibriumPoint(A, N):
    # Your code here
    if len(A)==1:
        return 1
    else:
        eqlist = []
        for i in range(1,N-1):
            if sum(A[:i]) == sum(A[i+1:]):
                eqlist.append(i+1)
        if sum(A[1:]) == 0:
            eqlist.insert(0,1)
        if sum(A[:N-1]) == 0:
            eqlist.append(N)
    if eqlist:
        return min(eqlist)
    else:
        return -1

================================================
FILE: Amazon/FindzeroSumSubArrays.py
================================================
def subArrayExists(arr,n):
    ##Your code here
    hashMap = {}
    out = []
    sum1 = 0
    for i in range(n):
        sum1 += arr[i]
        if sum1==0:
            out.append((0,i))
        al = []
        if sum1 in hashMap:
            al = hashMap.get(sum1)
            for it in range(len(al)):
                out.append((al[it]+1,i))
        al.append(i)
        hashMap[sum1] = al
    return len(out)
    
    
if __name__ == '__main__':
    t = int(input())
    for tcase in range(t):
        n = int(input())
        arr = list(map(int,input().strip().split()))
        print (subArrayExists(arr,n))

================================================
FILE: Amazon/ImplementSTRSTR.py
================================================
{
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        s,p =input().strip().split()
        print(strstr(s,p))

}
''' This is a function problem.You only need to complete the function given below '''
'''
	Your task is to return the index of the pattern
	present in the given string.
	
	Function Arguments: s (given text), p(given pattern)
	Return Type: Integer.
	
'''
def strstr(s,p):
    #code here
    import re
    loc = re.search(p,s)
    if loc is not None:
        return (loc.start())
    else:
        return -1

================================================
FILE: Amazon/JosephusProblem.py
================================================
{
import math
//Position this line where user code will be pasted.
    
def main():
    
    T=int(input())
    
    while(T>0):
        
        
        nk=[int(x) for x in input().strip().split()]
        n=nk[0]
        k=nk[1]
        
        print(josephus(n,k))
        
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#Complete this function
def josephus(n,k):
    #Your code here
    if n == 1:
        return n
    return ((josephus(n-1,k)+k-1)%n + 1)

================================================
FILE: Amazon/MaximumOfMinimumsOfAllWindowSizes.py
================================================
#User function Template for python3
"""
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.
Note: Window size varies from 1 to n.

Input:
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.

Output:
In each seperate line, print the array of numbers of size N for each of the considered window size 1, 2 , ..., N respectively.

User Task:
The task is to complete the function printMaxOfMin() which finds the maximum of minimum of every window size.

Constraints:
1 <= T <= 50
1 <= N <= 10^5
1 <= A[i] <= 10^6

Example:
Input: 
2
7
10 20 30 50 10 70 30
3
10 20 30
Output: 
70 30 20 10 10 10 10 
30 20 10

Explaination:
Testcase 1:
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.
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.
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.
Similarly other elements of output are computed.
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. 
"""
'''
Function Arguments :
      @param  : a(given array), n (size of array)
      @return : None, print the required Maxofmin array.
'''

def printMaxOfMin(a,n):
    # code here
    s = []
    left = [0 for i in range(n+1)]
    right = [0 for i in range(n+1)]
    left[:n] = [-1]*n
    right[:n] = [n]*n
    for i in range(0,n):
        while (len(s) != 0 and a[s[-1]] >= a[i]):  
            s.pop() 
        if (len(s) != 0):
            left[i] = s[-1]
        s.append(i)
    while (len(s) != 0):
        s.pop()
    for i in range(n-1,-1,-1):
        while (len(s) != 0 and a[s[-1]] >= a[i]):
            s.pop() 
        if (len(s) != 0):
            right[i] = s[-1]
        s.append(i)
    ans = [0]*(n+1)
    for i in range(0,n):
        length = right[i] - left[i] - 1
        ans[length] = max(ans[length],a[i])
    for i in range(n-1,0,-1):
        ans[i] = max(ans[i],ans[i+1])
    for i in range(1,n+1):
        print (ans[i],end=" ")
    print ("")
#{ 
#  Driver Code Starts
#Initial Template for Python 3

import atexit
import io
import sys

#Contributed by : Nagendra Jha

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register

def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

if __name__ == '__main__':
    test_cases = int(input())
    for cases in range(test_cases) :
        n = int(input())
        a = list(map(int,input().strip().split()))
        printMaxOfMin(a,n)

# } Driver Code Ends

================================================
FILE: Amazon/Possible_Words_Phone_Digits.py
================================================
{
#Initial Template for Python 3
import math
def main():
    
    T=int(input())
    
    while(T>0):
        
        N=int(input())
        a=[int(x) for x in input().strip().split()]
        
        possibleWords(a,N)
        
        print()
       
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
##Complete this function
def possibleWords(a,N):
    ##Your code here
    import itertools
    ph = {'abc':2,'def':3,'ghi':4,'jkl':5,'mno':6,'pqrs':7,'tuv':8,'wxyz':9}
    my_sts = []
    for x in a:
        for k,v in ph.items():
            if v == x:
                my_sts.append(k)
    if len(my_sts)>1:
        res = list(itertools.product(*my_sts))
        res = [''.join(u) for u in res]
        print (' '.join(i for i in res))
    else:
        print (' '.join(list(my_sts[0])))

================================================
FILE: Amazon/countOfInversionsArray.py
================================================
# GeeksForGeeks Code - Copied#
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for tt in range(t):
        n = int(input())
        a = list(map(int, input().strip().split()))
        print(Inversion_Count(a,n))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to return total number of inversions
	present in the array.
	
	Function Arguments: array a and size n
	Return Type: Integer 
'''
def Inversion_Count(arr,n):
    if a == sorted(a):
        return 0
    temp_arr = [0]*n
    return mergesort(arr,temp_arr,0,n-1)
    
def mergesort(arr,temp_arr,left,right):
    inv_count = 0
    if left < right:
        mid = (left + right)//2
        inv_count = mergesort(arr,temp_arr,left,mid)
        inv_count += mergesort(arr,temp_arr,mid+1,right)
        inv_count += merge(arr,temp_arr,left,mid,right)
    return inv_count
    
def merge(arr,temp_arr,left, mid, right): 
    # Merge the temp arrays back into arr[l..r] 
    i = left     # Initial index of first subarray 
    j = mid+1     # Initial index of second subarray 
    k = left     # Initial index of merged subarray 
    invcount = 0
    while i <= mid and j <= right: 
        if arr[i] <= arr[j]:
            temp_arr[k] = arr[i] 
            i += 1
        else: 
            temp_arr[k] = arr[j]
            invcount += (mid - i + 1)
            j += 1
        k += 1
    # Copy the remaining elements of L[], if there 
    # are any 
    while i <= mid: 
        temp_arr[k] = arr[i] 
        i += 1
        k += 1
    # Copy the remaining elements of R[], if there 
    # are any 
    while j <= right: 
        temp_arr[k] = arr[j] 
        j += 1
        k += 1
        
    for lr in range(left, right + 1): 
        arr[lr] = temp_arr[lr] 
    return invcount


================================================
FILE: Amazon/getAggregationsByParsing.py
================================================
#!/usr/bin/env python3.9
# Asked in Thrasio Interview Process
# Input:
    
sales_data = [{'channel':'Amazon', 'id':'AMZ456', 'sales':10, 'returns':0},
    {'channel':'Amazon', 'id':'AMZ123', 'sales':5, 'returns':2},
    {'channel':'Shopify', 'id':'1234', 'sales':15, 'returns':0},
    {'channel':'Target', 'id':'TGT456', 'sales':23, 'returns':5}
  ]
 
channel_thrasio_mapping = {
    'AMAZON':{'AMZ123':'THRASIO-987', 'AMZ456':'THRASIO-456'},
  'SHOPIFY':{'1234':'THRASIO-987', '5678':'THRASIO-321'}
  }
 
#Expected Output:
    # [
#   {'id':'THRASIO-987', 'net_sales':18, 'returns':2},
#   {'id':'THRASIO-456', 'net_sales':10, 'returns':0},
# ]

result = []
for k1,v1 in channel_thrasio_mapping.items():
    for k2,v2 in v1.items():
        temp_dict = {}
        temp_dict['id'] = v2
        all_sales = []
        all_returns = []
        for s in sales_data:
            if s['id'] == k2:
                all_sales.append(s['sales'])
                all_returns.append(s['returns'])
        net_sales = sum(all_sales)-sum(all_returns)
        returns = sum(all_returns)
        temp_dict['net_sales'] = net_sales
        temp_dict['returns'] = returns
        result.append(temp_dict)
    
    
#print (result)
unique_thrasio_ids = set([t['id'] for t in result])
#print (unique_thrasio_ids)

output = []
for utd in unique_thrasio_ids:
    final_result = {}
    final_result['id'] = utd
    final_result['net_sales'] = 0
    final_result['returns'] = 0
    for res in result:
        if res['id'] == utd:
            final_result['net_sales'] += res['net_sales']
            final_result['returns'] += res['returns']
    output.append(final_result)

print (output)


================================================
FILE: Amazon/keypadTyping.py
================================================
def keypadTyping(s):
    for c in s:
        print (mydict[c],end="")
    
if __name__ == '__main__':
    t = int(input())
    mydict = {'a':2,'b':2,'c':2,
              'd':3,'e':3,'f':3,
              'g':4,'h':4,'i':4,
              'j':5,'k':5,'l':5,
              'm':6,'n':6,'o':6,
              'p':7,'q':7,'r':7,'s':7,
              't':8,'u':8,'v':8,
              'w':9,'x':9,'y':9,'z':9}
    for tcase in range(t):
        s = input()
        keypadTyping(s)
        print ()

================================================
FILE: Amazon/merge2SortedLinkedLists.py
================================================
{
#Initial Template for Python 3
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n,m = map(int, input().strip().split())
        a = LinkedList() # create a new linked list 'a'.
        b = LinkedList() # create a new linked list 'b'.
        nodes_a = list(map(int, input().strip().split()))
        nodes_b = list(map(int, input().strip().split()))
        for x in nodes_a:
            a.append(x)
        for x in nodes_b:
            b.append(x)
        a.head = merge(a.head,b.head)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Function to merge two sorted lists in one
	using constant space.
	
	Function Arguments: head_a and head_b (head reference of both the sorted lists)
	Return Type: head of the obtained list after merger.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
	Contributed By: Nagendra Jha
'''
def merge(head_a,head_b):
    #code here
    global a
    elements = []
    curr_node = head_a
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    curr_node = head_b
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    elements = sorted(elements)
    a = LinkedList()
    for i in elements:
        a.append(i)
    return a.head

================================================
FILE: Amazon/missingSmallestPositiveNumber.py
================================================
{
#Initial Template for Python 3
import math
def main():
        T=int(input())
        while(T>0):
            
            n=int(input())
            
            arr=[int(x) for x in input().strip().split()]
            
            print(missingNumber(arr,n))
            
            T-=1
if __name__ == "__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
##Complete this function
def missingNumber(arr,n):
    #Your code here
    poss = [x for x in arr if x > 0]
    if poss:
        if poss == list(range(1,n+1)):
            return max(poss)+1
        else:
            min_poss = min(poss)
            max_poss = max(poss)
            total_range = list(range(1,max_poss+1))
            missingNumbers = set(total_range) - set(poss)
            return min(missingNumbers)
    else:
        return 0

================================================
FILE: Amazon/moveAllZerosToEndOfArray.py
================================================
def moveZerosToEnd(arr):
    arr_0 = [x for x in arr if x!=0]
    zeros = [0] * (len(arr)-len(arr_0))
    ans = arr_0 + zeros
    return " ".join(str(u) for u in ans)

if __name__ == '__main__':
    T = int(input())
    for t in range(T):
        N = int(input())
        arr = list(map(int,input().strip().split()))
        print (moveZerosToEnd(arr))

================================================
FILE: Amazon/parenthesisChecker.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
#Contributed by : Nagendra Jha
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    test_cases = int(input())
    for cases in range(test_cases) :
        #n = int(input())
        #n,k = map(int,imput().strip().split())
        #a = list(map(int,input().strip().split()))
        s = str(input())
        if ispar(s):
            print("balanced")
        else:
            print("not balanced")
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
Function Arguments :
		@param  : s (given string containing parenthesis) 
		@return : boolean True or False
'''

def isMatchingPair(c1,c2):
    if (c1=='(') & (c2==')'):
        return True
    elif (c1=='{') & (c2=='}'):
        return True
    elif (c1=='[') & (c2==']'):
        return True
    else:
        return False
        
def ispar(s):
    # code here
    import queue
    stack = queue.LifoQueue()
    
    for i in range(len(s)):
        if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')):
            stack.put(s[i])
        if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')):
            if stack.empty():
                return False
            elif not isMatchingPair(stack.get(),s[i]):
                return False
        
    if stack.empty():
        return True
    else:
        return False

================================================
FILE: Amazon/relativeSorting.py
================================================
def relativeSorting(A1,A2):
    common_elements = set(A1).intersection(set(A2))
    extra = set(A1).difference(set(A2))
    out = []
    for i in A2:
        s = [i] * A1.count(i)
        out.extend(s)
    extra_out = []
    for j in extra:
        u = [j] * A1.count(j)
        extra_out.extend(u)
    out = out + sorted(extra_out)
    return " ".join(str(i) for i in out)
    
if __name__ == '__main__':
    t = int(input())
    for tcase in range(t):
        N,M = list(map(int,input().strip().split()))
        A1 = list(map(int,input().strip().split()))
        A2 = list(map(int,input().strip().split()))
        print (relativeSorting(A1,A2))

================================================
FILE: Amazon/rotateLinkedListByKelements.py
================================================
{
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
class LinkedList:
    def __init__(self):
        self.head = None
    def push(self, new_data):
        new_node = Node(new_data)
        new_node.next = self.head
        self.head = new_node
    def printList(self):
        temp = self.head
        while(temp):
            print(temp.data, end=" ")
            # arr.append(str(temp.data))
            temp = temp.next
        print("")
if __name__ == '__main__':
    start = LinkedList()
    t = int(input())
    while(t > 0):
        llist = LinkedList()
        n = int(input())
        values = list(map(int, input().strip().split()))
        for i in reversed(values):
            llist.push(i)
        k = int(input())
        new_head = rotateList(llist.head, k)
        llist.head = new_head
        llist.printList()
        t -= 1
# Contributed by: Harshit Sidhwa

}
''' This is a function problem.You only need to complete the function given below '''
# Your task is to complete this function
'''
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
'''
# This function should rotate list counter-
# clockwise by k and return new head (if changed) 
def rotateList(head, k):
    # code here
    global llist
    llist = LinkedList()
    C = 0
    curr_node = head
    part1 = []
    part2 = []
    while curr_node != None:
        if C <= k-1:
            part1.append(curr_node.data)
        elif C > k-1:
            part2.append(curr_node.data)
        C += 1
        curr_node = curr_node.next
    total = reversed(part2 + part1)
    for i in total:
        llist.push(i)
    return llist.head

================================================
FILE: AmericanExpress/README.md
================================================
# Interview Process for Engineer - II (2021) (Personal):  
### First Round - Coding Round: Online Coding Round with time management.  
### Second Round - Design:  
+ Design an Application that serves machine learning model results in real-time (Design a feedback ingestion system and notifications pusher) - Brush upon 
system design concepts, NoSQL Databases, caching, load balancer frameworks, distributed computing fundamentals, APIs, software design patterns.  

### Third Round - Technical:  
+ 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 
like spark, Dask etc - performance and efficient design matters!  - very good question, completely depends on the distributed and parallel processing paradigms and 
operating systems knowledge.  


================================================
FILE: Athena-Health/README.md
================================================
# Interview Process for SMTS (Senior Member of Technical Staff) - 2021:  
### First Round - Coding (Data Structures and Algorithms):  
+ 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).  
+ Given an unsorted array, Find the median of the given array (Do not use any libraries and functions, Raw code has to be written).  
  
  
### Second Round - Design:  
+ In-Depth questions on BSTs and graphs.  
+ 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.  

### Third Round - Managerial:  
+ Questions on your technical experience and projects you have done.  
+ Challenges in the projects, how are scaling issues resolved, Team work, Milestones achieved etc.  
+ Questions on Deployment process followed and tools used for deploying codebase - devops architecture, CI/CD, Docker, Kubernetes, Service mesh and containerization etc

### Fourth Round - HR round:  
+ Questions are similar to questions from any other HR round.  
+ what are you looking for? what are your career aspirations?  
+ what are your interests and why are you interested in athenahealth?
+ Any other doubts and clarifications on the role, Planning connects with Hiring manager etc.


================================================
FILE: Betterworks/README.md
================================================
# Hiring process for Betterworks Software Engineer Role (Personal Experience):  
  
## First round:  
+ 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.  
  
## Second round:  
+ Technical screening on basic coding questions.  
+ 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).  
+ sorting techniques, python built-in data structures and questions on the same.  
+ questions on python decorators.  
  
## Third round:  
+ Hands-on Assignment where you have to build a working prototype of an API (Assignment will be shared in the form of PDF).  
  
## Fourth round:  
+ Questions on pandas data analysis techniques  groupby, aggregations, distributions, visualizing the bar charts, boxplots.  
+ SQL - primary keys, foreign keys, composite keys, Indexes, star and snowflake schemas.  
+ 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).  
+ 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.  
+ Questions on REST API, design techniques etc.  


================================================
FILE: Betterworks/print.py
================================================
"""
Given a dictionary of elements:
    mydict = {'one':1,
              'two':2,
              'three':3,
              'four':4,
              'five':5}
    print the sequence of elements in the following fashion:
        {'n':1,'w':2,'r':3,'ou':4,'iv':5}
        
"""

mydict = {'one':1,
              'two':2,
              'three':3,
              'four':4,
              'five':5}

def doop(mydict):
    if len(mydict) == 0:
        return "no data"
    res = {}
    for k,v in mydict.items():
        leng = len(k)
        if leng%2 != 0:
            res.update({k[(leng-1)//2]:v})
        else:
            key = ''.join([k[(leng-1)//2],k[(leng+1)//2]])
            res.update({key:v})
    return res

print (doop(mydict))

================================================
FILE: Bloomberg/moveAllZerosToEndOfArray.py
================================================
def moveZerosToEnd(arr):
    arr_0 = [x for x in arr if x!=0]
    zeros = [0] * (len(arr)-len(arr_0))
    ans = arr_0 + zeros
    return " ".join(str(u) for u in ans)

if __name__ == '__main__':
    T = int(input())
    for t in range(T):
        N = int(input())
        arr = list(map(int,input().strip().split()))
        print (moveZerosToEnd(arr))

================================================
FILE: BrightMoney/Knapsack.py
================================================
"""
0-1 Knapsack problem

"""

================================================
FILE: BrightMoney/LongestBalancedSubstring.py
================================================
"""
Longest balanced substring given a string containing only parenthesis (open and
closed curly braces)

Refer https://www.geeksforgeeks.org/length-of-the-longest-valid-substring/
along with the length, also print the start and end indices of this longest substring

Refer below custom addition to the existing code

"""


def findMaxLen(string): 
    n = len(string) 
  
    # Create a stack and push -1 as initial index to it. 
    stk = [] 
    stk.append(-1) 
  
    # Initialize result 
    result = 0
    tracker = []
  
    # Traverse all characters of given string 
    for i in range(n): 
      
        # If opening bracket, push index of it 
        if string[i] == '{': 
            stk.append(i) 
  
        else:    # If closing bracket, i.e., str[i] = '}' 
      
            # Pop the previous opening bracket's index 
            stk.pop() 
      
            # Check if this length formed with base of 
            # current valid substring is more than max  
            # so far 
            if len(stk) != 0: 
                if result < i - stk[len(stk)-1]:
                    result = i - stk[len(stk)-1]
                    tracker.append((result,i))
  
            # If stack is empty. push current index as  
            # base for next valid substring (if any) 
            else: 
                stk.append(i) 
  
    return result,tracker

#string = "{{{}"
#string = "}{}{}}"
string = "{}{{}}}}}"
result,tracker = findMaxLen(string)
for t in tracker:
    if t[0] == result:
        end_index = t[1]
        
# length of longest substring (balanced)
print (result)

# print (start and end locations of that substring)
print (" ".join([str(end_index - result + 2),str(end_index + 1)]))

================================================
FILE: BrightMoney/README.md
================================================
# Coding questions on DoSelect Platform (Personal Experience) (Data Science roles - ML Engineering) (4 Coding questions are added here)  
+  This process is different from Data analyst process.  
  
# Interview Process for Data Analyst position:  
## First round - DoSelect Assessment for Data Analyst positions/Word Document on email:  
+ There are different kinds of assessments being used by BrightMoney for Data analyst positions:  
  - 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).  
  - 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)  
  
## Second round - Business Case study from the founder of Brightmoney.co:  
+ 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).  


================================================
FILE: BrightMoney/countDistinctValidPANNumbers.py
================================================
"""
Given a paragraph of P words, find all valid PAN card numbers in that paragraph
"""

================================================
FILE: BrightMoney/printSpirally.py
================================================
"""
Given an integer n, generate a square matrix from entries from 1 to n**2 in 
spiral pattern

"""

def generateMatrix(n):
    if n <= 0:
        return []
    result = [[None for i in range(n)] for j in range(n)]
    xBeg,xEnd = 0,n-1
    yBeg,yEnd = 0,n-1
    current = 1
    while (True):
        for i in range(yBeg,yEnd+1):
            result[xBeg][i] = current
            current += 1
        xBeg += 1
        if (xBeg > xEnd):
            break
        for i in range(xBeg,xEnd+1):
            result[i][yEnd] = current
            current += 1
        yEnd -= 1
        if (yEnd < yBeg):
            break
        for i in range(yEnd,yBeg-1,-1):
            result[xEnd][i] = current
            current += 1
        xEnd -= 1
        if (xEnd < xBeg):
            break
        for i in range(xEnd,xBeg-1,-1):
            result[i][yBeg] = current
            current += 1
        yBeg += 1
        if (yBeg > yEnd):
            break
    return result
        
rows = generateMatrix(9)
for row in rows:
    print (" ".join(str(i) for i in row))

================================================
FILE: Busigence/README.md
================================================
# Interview Process - Personal (Data Engineer - Python/Pyspark/Scala-spark) - 2021:  
### First round:  
+ Take Home assignment on Spark coding.  
+ The solutions added above are correct (Got selected to next round) 👍 🙂.  


================================================
FILE: Busigence/Vikas_Chitturi.ipynb
================================================
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "DATA ENGINEER - PYTHON PYSPARK"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This test consits of fifteen problems. You are required to write your code in cell below each problem and output the result in cell next to it "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Total Time Allowed: 3 hours"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Style1: 10 markes each shall be awarded for correct solution coded in object oriented paradign in Python3 <br>\n",
    "Style2: 15 marks each shall be awarded for correct solution coded in functional programming paradigm (lamda, map, reduce, filter etc) in Python3 <br>\n",
    "Style3: 20 marks each shall be awarded for correct solution coded in functional programming paradigm (dataframes, map, reduce, filter etc) in PySpark3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Rename and Save the notebook with your FirstName_LastName (eg. Sahil_Gupta.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Vikas Veerabhadra Chitturi\n",
    "#XXXXXXXXXXXXXXXX\n",
    "#+91-XXXXXXXXXX"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "********************************************* Test starts here **************************************************"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "INSTRUCTIONS:\n",
    "    1. You are required to download and import five CSV files, one json file and one xml file\n",
    "    2. You would need to understand business involved behind CRM database tables. This is important\n",
    "    3. Code must be in Python3/PySpark3\n",
    "    4. Either your code should output something or leave the comment \"#solution code here\" as it is. We shall use 'Run All' in notebook and it shouldn't result error\n",
    "    5. Test the entire notebook before uploading to Google Form provided\n",
    "    6. You can use any Python3 library (two are imported already) or PySpark3 library. There is no restriction\n",
    "    7. Output fieldname to be displayed are marked as single quaotes '' in problem statement. You should use same field alias names whereever required\n",
    "    8. Notation for dataframe and/or array must be local to a problem's solution. Eg. Dataframe \"test\" for problem 8 should be df_prb8_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pyspark.sql import SparkSession\n",
    "from pyspark.sql.functions import *\n",
    "from pyspark.sql.types import *\n",
    "from collections import defaultdict\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<pyspark.sql.session.SparkSession object at 0x7fa7a6083040>\n"
     ]
    }
   ],
   "source": [
    "#Please make sure this notebook is run on spark installed cluster/environment - Data processing is done in pyspark\n",
    "spark = SparkSession.builder\\\n",
    "          .master(\"local[4]\")\\\n",
    "          .appName(\"Assignment\")\\\n",
    "          .getOrCreate()\n",
    "print (spark)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sales Teams...\n",
      "[Row(sales_agent='Donn Cantrell', manager='Rocco Neubert', regional_office='Central'), Row(sales_agent='James Ascencio', manager='Summer Sewald', regional_office='West'), Row(sales_agent='Vicki Laflamme', manager='Celia Rouche', regional_office='West'), Row(sales_agent='Niesha Huffines', manager='Melvin Marxen', regional_office='East'), Row(sales_agent='Kami Bicknell', manager='Summer Sewald', regional_office='West')]\n",
      "Accounts....\n",
      "[Row(account='Sunnamplex', revenue='4592.96', employees='13938.0'), Row(account='Silis', revenue='5339.57', employees='18053.0'), Row(account='Groovestreet', revenue='2728.86', employees='6486.0'), Row(account='Donware', revenue='2009.52', employees='3409.0'), Row(account='Wonka Industries', revenue='4962.27', employees='4687.0')]\n",
      "Clicks....\n",
      "[Row(created_on='2016-11-14', source='Referral', industry='IT'), Row(created_on='2016-11-14', source='Social', industry='IT'), Row(created_on='2016-11-14', source='Paid', industry='SaaS'), Row(created_on='2016-11-14', source='Direct', industry='SaaS'), Row(created_on='2016-11-15', source='Organic', industry='Health Care')]\n",
      "Products....\n",
      "[Row(product='GTXAdvanced', sales_price='649.0'), Row(product='GTXBasic', sales_price='641.0'), Row(product='MGRPFU', sales_price='3959.0'), Row(product='MGRPFS', sales_price='64.0'), Row(product='GTXPlusBasic', sales_price='1279.0')]\n",
      "Sales Pipeline....\n",
      "[Row(account='Sunnamplex', opportunity_id='67HY0MW7', sales_agent='Donn Cantrell', deal_stage='Won', product='GTXBasic', close_date='2017-05-06', close_value='500.0', created_on='2017-04-24'), Row(account=None, opportunity_id='MA82HVCI', sales_agent='James Ascencio', deal_stage='In_Progress', product='GTXPro', close_date=None, close_value=None, created_on='2017-06-15'), Row(account=None, opportunity_id='BRL1KVVH', sales_agent='Vicki Laflamme', deal_stage='Lost', product='GTXBasic', close_date='2017-08-03', close_value='0.0', created_on='2017-05-19'), Row(account='Silis', opportunity_id='R22O68FF', sales_agent='Niesha Huffines', deal_stage='Won', product='GTXBasic', close_date='2017-06-27', close_value='524.0', created_on='2017-03-21'), Row(account='Silis', opportunity_id='J78AK31N', sales_agent='Kami Bicknell', deal_stage='Won', product='MGRPFU', close_date='2017-08-04', close_value='4794.0', created_on='2017-05-15')]\n"
     ]
    }
   ],
   "source": [
    "#import CSVs here\n",
    "df_sales_teams = spark.read.format('csv')\\\n",
    "                      .option(\"header\",\"true\")\\\n",
    "                      .load(\"data/sales_teams.csv\")\n",
    "df_accounts = spark.read.format('csv')\\\n",
    "                      .option(\"header\",\"true\")\\\n",
    "                      .load(\"data/accounts.csv\")\n",
    "df_clicks = spark.read.format('csv')\\\n",
    "                      .option(\"header\",\"true\")\\\n",
    "                      .load(\"data/clicks.csv\")\n",
    "df_products = spark.read.format('csv')\\\n",
    "                      .option(\"header\",\"true\")\\\n",
    "                      .load(\"data/products.csv\")\n",
    "df_sales_pipeline = spark.read.format('csv')\\\n",
    "                      .option(\"header\",\"true\")\\\n",
    "                      .load(\"data/sales_pipeline.csv\")\n",
    "\n",
    "print (\"Sales Teams...\")\n",
    "print (df_sales_teams.take(5))\n",
    "\n",
    "print (\"Accounts....\")\n",
    "print (df_accounts.take(5))\n",
    "\n",
    "print (\"Clicks....\")\n",
    "print (df_clicks.take(5))\n",
    "\n",
    "print (\"Products....\")\n",
    "print (df_products.take(5))\n",
    "\n",
    "print (\"Sales Pipeline....\")\n",
    "print (df_sales_pipeline.take(5))\n",
    "\n",
    "#import JSONs here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Refer & Use five CSVs to answer problem 1-10 below"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 1: Display 'Manager' and 'Grand Total Sales', for sales done by the sales agents reporting these managers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+-------------+-------------+-----------+-----------+\n",
      "|  sales_agent|      manager| deal_stage|close_value|\n",
      "+-------------+-------------+-----------+-----------+\n",
      "|Donn Cantrell|Rocco Neubert|        Won|      444.0|\n",
      "|Donn Cantrell|Rocco Neubert|In_Progress|       null|\n",
      "|Donn Cantrell|Rocco Neubert|       Lost|        0.0|\n",
      "|Donn Cantrell|Rocco Neubert|        Won|     7695.0|\n",
      "|Donn Cantrell|Rocco Neubert|        Won|     5531.0|\n",
      "|Donn Cantrell|Rocco Neubert|In_Progress|       null|\n",
      "|Donn Cantrell|Rocco Neubert|        Won|     7381.0|\n",
      "|Donn Cantrell|Rocco Neubert|        Won|      565.0|\n",
      "|Donn Cantrell|Rocco Neubert|In_Progress|       null|\n",
      "|Donn Cantrell|Rocco Neubert|        Won|     7905.0|\n",
      "+-------------+-------------+-----------+-----------+\n",
      "only showing top 10 rows\n",
      "\n",
      "14277\n",
      "+----------------+-----------------+\n",
      "|         manager|grand_total_sales|\n",
      "+----------------+-----------------+\n",
      "|    Celia Rouche|        2518466.0|\n",
      "|   Rocco Neubert|        3346813.0|\n",
      "|   Melvin Marxen|        4265901.0|\n",
      "|   Summer Sewald|        2915362.0|\n",
      "|      Cara Losch|        1861751.0|\n",
      "|Dustin Brinkmann|        3028635.0|\n",
      "+----------------+-----------------+\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "#joining sales_teams and sales_pipeline tables\n",
    "df_st_sp_prob1 = df_sales_teams.select(\"sales_agent\",\"manager\").alias(\"a\")\\\n",
    "                         .join(df_sales_pipeline.select(\"sales_agent\",\"deal_stage\",\"close_value\").alias(\"b\"),\n",
    "                               on=col(\"a.sales_agent\")==col(\"b.sales_agent\"),how='left')\\\n",
    "                         .select([col(\"a.sales_agent\"),col(\"a.manager\"),col(\"b.deal_stage\"),col(\"b.close_value\")])\n",
    "df_st_sp_prob1.show(10) \n",
    "print (df_st_sp_prob1.count())\n",
    "#putting a filter on deal_stage=='Won' because it is considered as successful sale completed and close_value is the\n",
    "#final value for which product is sold after negotiation\n",
    "df_st_sp_prob1 = df_st_sp_prob1.filter(col(\"deal_stage\")==\"Won\")\n",
    "df_st_sp_prob1 = df_st_sp_prob1.withColumn(\"close_value\",df_st_sp_prob1[\"close_value\"].cast(DoubleType()))\n",
    "result_prob1 = df_st_sp_prob1.groupBy(\"manager\").agg(sum(\"close_value\").alias(\"grand_total_sales\"))\n",
    "result_prob1.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 2: Display 'Sales Agents' and 'Sales' for those sales where product sold at profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------+-----------------+----------+------------+-----------+------------+\n",
      "|opportunity_id|      sales_agent|deal_stage|     product|final_price|actual_price|\n",
      "+--------------+-----------------+----------+------------+-----------+------------+\n",
      "|      67HY0MW7|    Donn Cantrell|       Won|    GTXBasic|      500.0|       641.0|\n",
      "|      R22O68FF|  Niesha Huffines|       Won|    GTXBasic|      524.0|       641.0|\n",
      "|      J78AK31N|    Kami Bicknell|       Won|      MGRPFU|     4794.0|      3959.0|\n",
      "|      8I9PRPGN|Versie Hillebrand|       Won|      MGRPFS|       67.0|        64.0|\n",
      "|      4VHUTHOJ|    Kami Bicknell|       Won|GTXPlusBasic|     1480.0|      1279.0|\n",
      "|      TMJ0OJ0B|  Kary Hendrixson|       Won|    GTXBasic|      635.0|       641.0|\n",
      "|      MD4PBMNN|    Anna Snelling|       Won|      MGRPFU|     3842.0|      3959.0|\n",
      "|      1XPVT5AY|  Kary Hendrixson|       Won|  GTXPlusPro|     5055.0|      6395.0|\n",
      "|      IH2QISS9|  Kary Hendrixson|       Won|      GTXPro|     4889.0|      5624.0|\n",
      "|      7JJ73XCX|   James Ascencio|       Won|GTXPlusBasic|     1226.0|      1279.0|\n",
      "|      T8QRTV6F|   James Ascencio|       Won|  GTXPlusPro|     9150.0|      6395.0|\n",
      "|      C7NFUAR6|Marty Freudenburg|       Won|GTXPlusBasic|     1380.0|      1279.0|\n",
      "|      NXRZZBVS|  Lajuana Vencill|       Won|      MGRPFU|     3620.0|      3959.0|\n",
      "|      H7ZQUWDJ|     Reed Clapper|       Won|    GTXBasic|      660.0|       641.0|\n",
      "|      YV47EGIC|    Anna Snelling|       Won|      MGRPFS|       44.0|        64.0|\n",
      "|      SC4LUMPZ|     Elease Gluck|       Won|      MGRPFS|       64.0|        64.0|\n",
      "|      ZES3NR0F|Versie Hillebrand|       Won|      MGRPFS|       54.0|        64.0|\n",
      "|      KJ1JOOQ0|  Niesha Huffines|       Won|      MGRPFS|       61.0|        64.0|\n",
      "|      ZHV68QKO|     Reed Clapper|       Won|      GTXPro|     4551.0|      5624.0|\n",
      "|      4RE1ST7V|    Kami Bicknell|       Won|  GTXPlusPro|     5213.0|      6395.0|\n",
      "+--------------+-----------------+----------+------------+-----------+------------+\n",
      "only showing top 20 rows\n",
      "\n",
      "6438\n",
      "+--------------+------------------+------------+-----------+------------+\n",
      "|opportunity_id|       sales_agent|     product|final_price|actual_price|\n",
      "+--------------+------------------+------------+-----------+------------+\n",
      "|      J78AK31N|     Kami Bicknell|      MGRPFU|     4794.0|      3959.0|\n",
      "|      8I9PRPGN| Versie Hillebrand|      MGRPFS|       67.0|        64.0|\n",
      "|      4VHUTHOJ|     Kami Bicknell|GTXPlusBasic|     1480.0|      1279.0|\n",
      "|      T8QRTV6F|    James Ascencio|  GTXPlusPro|     9150.0|      6395.0|\n",
      "|      C7NFUAR6| Marty Freudenburg|GTXPlusBasic|     1380.0|      1279.0|\n",
      "|      H7ZQUWDJ|      Reed Clapper|    GTXBasic|      660.0|       641.0|\n",
      "|      8S4H8GNZ|      Reed Clapper|      MGRPFU|     4750.0|      3959.0|\n",
      "|      P007M3B8| Marty Freudenburg|      MGRPFS|       75.0|        64.0|\n",
      "|      KI49INQW|  Gladys Colclough|GTXPlusBasic|     1524.0|      1279.0|\n",
      "|      2NAKBIH8|      Reed Clapper|      GTXPro|     7007.0|      5624.0|\n",
      "|      TGYPRG6Y|    Wilburn Farren|GTXPlusBasic|     1566.0|      1279.0|\n",
      "|      H8ONBK8M|   Kary Hendrixson|GTXPlusBasic|     1631.0|      1279.0|\n",
      "|      WB5W4F6P|      Reed Clapper|      GTXPro|     6894.0|      5624.0|\n",
      "|      VB2E4FRU|      Elease Gluck|      MGRPFU|     4712.0|      3959.0|\n",
      "|      VUNCUB75|Jonathan Berthelot|GTXPlusBasic|     1307.0|      1279.0|\n",
      "|      9UAMZCLW|      Elease Gluck|      MGRPFU|     4389.0|      3959.0|\n",
      "|      FH7HBET2|       Moses Frase|GTXPlusBasic|     1509.0|      1279.0|\n",
      "|      WHRDPR4H|   Darcel Schlecht|    GTXBasic|      875.0|       641.0|\n",
      "|      9L5HPLM6|   Niesha Huffines|    GTXBasic|      688.0|       641.0|\n",
      "|      AZF4JUJH|     Kami Bicknell|      MGRPFS|       66.0|        64.0|\n",
      "+--------------+------------------+------------+-----------+------------+\n",
      "only showing top 20 rows\n",
      "\n",
      "3386\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "#joining sales_pipeline and products tables to get the mapping of actual and final prices\n",
    "df_sp_prod_prob2 = df_sales_pipeline.filter(col(\"deal_stage\")==\"Won\")\\\n",
    "                         .select(\"opportunity_id\",\"sales_agent\",\"deal_stage\",\"product\",\"close_value\").alias(\"a\")\\\n",
    "                         .join(df_products.select(\"product\",\"sales_price\").alias(\"b\"),\n",
    "                               on=col(\"a.product\")==col(\"b.product\"),how='left')\\\n",
    "                         .select([col(\"a.opportunity_id\"),col(\"a.sales_agent\"),col(\"a.deal_stage\"),col(\"a.product\"),\n",
    "                                  col(\"a.close_value\").alias(\"final_price\"),\n",
    "                                  col(\"b.sales_price\").alias(\"actual_price\")])\n",
    "df_sp_prod_prob2.show(20)\n",
    "print (df_sp_prod_prob2.count())\n",
    "\n",
    "#profit means final price (close_value) is greater than actual price (sales_price)\n",
    "result_prob2 = df_sp_prod_prob2.where(col(\"final_price\") > col(\"actual_price\"))\n",
    "result_prob2 = result_prob2.select(\"opportunity_id\",\"sales_agent\",\"product\",\"final_price\",\"actual_price\")\n",
    "result_prob2.show()\n",
    "print (result_prob2.count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 3: Display the 'Opportunity ID' and 'Days Taken to Close', for opportunities those got closed within a month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------+----------------+\n",
      "|opportunity_id|DaysTakenToClose|\n",
      "+--------------+----------------+\n",
      "|      67HY0MW7|              12|\n",
      "|      R22O68FF|              98|\n",
      "|      J78AK31N|              81|\n",
      "|      8I9PRPGN|              41|\n",
      "|      4VHUTHOJ|               1|\n",
      "|      TMJ0OJ0B|              10|\n",
      "|      MD4PBMNN|              95|\n",
      "|      1XPVT5AY|              57|\n",
      "|      IH2QISS9|              94|\n",
      "|      7JJ73XCX|              61|\n",
      "|      T8QRTV6F|              10|\n",
      "|      C7NFUAR6|              65|\n",
      "|      NXRZZBVS|              52|\n",
      "|      H7ZQUWDJ|               9|\n",
      "|      YV47EGIC|              65|\n",
      "|      SC4LUMPZ|              53|\n",
      "|      ZES3NR0F|              89|\n",
      "|      KJ1JOOQ0|              13|\n",
      "|      ZHV68QKO|              89|\n",
      "|      4RE1ST7V|              22|\n",
      "|      8S4H8GNZ|              65|\n",
      "|      P007M3B8|             109|\n",
      "|      KI49INQW|              50|\n",
      "|      2NAKBIH8|              87|\n",
      "|      QRYFOK47|              36|\n",
      "|      3X1QOEBM|              68|\n",
      "|      TGYPRG6Y|              92|\n",
      "|      H8ONBK8M|              56|\n",
      "|      H0NRZ2VX|              22|\n",
      "|      NC7SHGMD|              71|\n",
      "+--------------+----------------+\n",
      "only showing top 30 rows\n",
      "\n",
      "6438\n",
      "+--------------+----------------+\n",
      "|opportunity_id|DaysTakenToClose|\n",
      "+--------------+----------------+\n",
      "|      67HY0MW7|              12|\n",
      "|      4VHUTHOJ|               1|\n",
      "|      TMJ0OJ0B|              10|\n",
      "|      T8QRTV6F|              10|\n",
      "|      H7ZQUWDJ|               9|\n",
      "|      KJ1JOOQ0|              13|\n",
      "|      4RE1ST7V|              22|\n",
      "|      H0NRZ2VX|              22|\n",
      "|      VB2E4FRU|               8|\n",
      "|      FLXHSKT4|              13|\n",
      "|      WHRDPR4H|              12|\n",
      "|      IF0LPAQA|              15|\n",
      "|      Z1L5OUDD|              12|\n",
      "|      NLKOGB9I|              18|\n",
      "|      MTEPBRDZ|               6|\n",
      "|      RVTAL02P|              11|\n",
      "|      4E73L1M3|              28|\n",
      "|      NASE5KTW|              12|\n",
      "|      LXTS18HY|               6|\n",
      "|      WA0B8VK9|              18|\n",
      "|      SPR1ZGYU|              30|\n",
      "|      L3BMFOAZ|               9|\n",
      "|      2CFS9GLC|              10|\n",
      "|      K1DFBO5B|              13|\n",
      "|      TRN9B8S9|               1|\n",
      "|      GCNZ7C5H|              13|\n",
      "|      ZWSHCZO3|              18|\n",
      "|      JEFB24SP|              18|\n",
      "|      9UXVO2DF|               7|\n",
      "|      WCP1FZLS|              10|\n",
      "+--------------+----------------+\n",
      "only showing top 30 rows\n",
      "\n",
      "2196\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "#Filter on deal_stage and parsing the date column to date type and using datediff\n",
    "result_prob3 = df_sales_pipeline.filter(col(\"deal_stage\")==\"Won\")\\\n",
    "                                .withColumn(\"DaysTakenToClose\", \n",
    "                                            datediff(to_date(\"close_date\",\"yyyy-MM-dd\"),\n",
    "                                                     to_date(\"created_on\",\"yyyy-MM-dd\"))).select(\"opportunity_id\",\"DaysTakenToClose\")\n",
    "result_prob3.show(30)\n",
    "print (result_prob3.count())\n",
    "\n",
    "#hardcoding the range of month as 30 for now\n",
    "result_prob3 = result_prob3.filter(col(\"DaysTakenToClose\") <= 30)\n",
    "result_prob3.show(30)\n",
    "print (result_prob3.count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 4: Display product(s) got maximum leads (by count) generated from paid source"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#solution code here\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 5: Display 'Sales Agent' and 'Opportunity Count', for those sales agents who lost atleast two opportunties"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+------------------+----------------------+\n",
      "|       sales_agent|numOfLostOpportunities|\n",
      "+------------------+----------------------+\n",
      "|   Darcel Schlecht|                   337|\n",
      "|     Kami Bicknell|                   134|\n",
      "|    Vicki Laflamme|                   162|\n",
      "|      Elease Gluck|                    62|\n",
      "|Jonathan Berthelot|                   185|\n",
      "|   Daniell Hammack|                    80|\n",
      "|     Anna Snelling|                   140|\n",
      "|      Cassey Cress|                   137|\n",
      "|     Garret Kinder|                    63|\n",
      "|    Markita Hansen|                   115|\n",
      "|      Reed Clapper|                    87|\n",
      "|Rosie Papadopoulos|                    56|\n",
      "|   Maureen Marcano|                   119|\n",
      "|  Violet Mclelland|                   111|\n",
      "|  Gladys Colclough|                   149|\n",
      "|         Boris Faz|                    63|\n",
      "|    Wilburn Farren|                    44|\n",
      "| Versie Hillebrand|                   118|\n",
      "| Marty Freudenburg|                   120|\n",
      "|    Cecily Lampkin|                    86|\n",
      "+------------------+----------------------+\n",
      "only showing top 20 rows\n",
      "\n",
      "30\n",
      "+------------------+----------------------+\n",
      "|       sales_agent|numOfLostOpportunities|\n",
      "+------------------+----------------------+\n",
      "|   Darcel Schlecht|                   337|\n",
      "|     Kami Bicknell|                   134|\n",
      "|    Vicki Laflamme|                   162|\n",
      "|      Elease Gluck|                    62|\n",
      "|Jonathan Berthelot|                   185|\n",
      "|   Daniell Hammack|                    80|\n",
      "|     Anna Snelling|                   140|\n",
      "|      Cassey Cress|                   137|\n",
      "|     Garret Kinder|                    63|\n",
      "|    Markita Hansen|                   115|\n",
      "|      Reed Clapper|                    87|\n",
      "|Rosie Papadopoulos|                    56|\n",
      "|   Maureen Marcano|                   119|\n",
      "|  Violet Mclelland|                   111|\n",
      "|  Gladys Colclough|                   149|\n",
      "|         Boris Faz|                    63|\n",
      "|    Wilburn Farren|                    44|\n",
      "| Versie Hillebrand|                   118|\n",
      "| Marty Freudenburg|                   120|\n",
      "|    Cecily Lampkin|                    86|\n",
      "+------------------+----------------------+\n",
      "only showing top 20 rows\n",
      "\n",
      "30\n",
      "validation test:  True\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "result_prob5 = df_sales_pipeline.filter(col(\"deal_stage\")==\"Lost\")\\\n",
    "                                .select(\"sales_agent\",\"opportunity_id\")\\\n",
    "                                .groupBy(\"sales_agent\").agg(count(\"opportunity_id\").alias(\"numOfLostOpportunities\"))\n",
    "result_prob5.show(20)\n",
    "print (result_prob5.count())\n",
    "\n",
    "result_prob5 = result_prob5.filter(col(\"numOfLostOpportunities\") >= 2)\n",
    "\n",
    "result_prob5.show(20)\n",
    "print (result_prob5.count())\n",
    "\n",
    "#validation test\n",
    "print (\"validation test: \", result_prob5.agg(sum(\"numOfLostOpportunities\")).collect()[0][0] == df_sales_pipeline.filter(col(\"deal_stage\")==\"Lost\").count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 6: Display in ascending order of revenue, 'Account' and 'Revenue' for telecom accounts "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+-------+\n",
      "|             account|revenue|\n",
      "+--------------------+-------+\n",
      "|          Stanredtax|  14.79|\n",
      "|          Fasehatice|   19.2|\n",
      "|            Kan-code|  22.63|\n",
      "|           Treequote|   73.1|\n",
      "|           Konmatfix|  82.96|\n",
      "|Olivia Pope & Ass...|  97.94|\n",
      "|         Donquadtech| 110.88|\n",
      "|           Warephase| 130.62|\n",
      "|        Soylent Corp| 136.89|\n",
      "|         Iselectrics| 138.63|\n",
      "|              Yearin| 144.68|\n",
      "|           Ganjaflex|  161.8|\n",
      "|     Sterling Cooper| 204.47|\n",
      "|            Rangreen| 211.12|\n",
      "|            Xx-zobam| 221.86|\n",
      "|              Hatfan| 223.54|\n",
      "|            Betatech| 239.22|\n",
      "|           Duff Beer| 244.32|\n",
      "|         Good Burger| 247.91|\n",
      "|            Blackzim| 256.32|\n",
      "|             Nam-zim| 369.58|\n",
      "|         Krusty Krab| 372.21|\n",
      "|               Hooli| 374.84|\n",
      "|             Finhigh| 398.18|\n",
      "|            Hottechi|  431.1|\n",
      "|          Bubba Gump| 459.79|\n",
      "|          Green-Plus| 562.28|\n",
      "|              Sonron| 588.46|\n",
      "|             Codehow| 638.03|\n",
      "|          Lexiqvolax| 652.53|\n",
      "+--------------------+-------+\n",
      "only showing top 30 rows\n",
      "\n",
      "97\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "df_accounts = df_accounts.withColumn(\"revenue\",df_accounts[\"revenue\"].cast(DoubleType()))\n",
    "result_prob6 = df_accounts.orderBy(\"revenue\",ascending=True).select(\"account\",\"revenue\")\n",
    "result_prob6.show(30)\n",
    "print (result_prob6.count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 7: Display by revenue generated, bottom five 'Industries' and 'Revenue'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+-----------------+-------+\n",
      "|          account|revenue|\n",
      "+-----------------+-------+\n",
      "|   Dalttechnology| 6085.6|\n",
      "|            Silis|5339.57|\n",
      "|            Newex|5093.78|\n",
      "| Wonka Industries|4962.27|\n",
      "|         Faxquote|4939.54|\n",
      "|       Sunnamplex|4592.96|\n",
      "|            Isdom|4514.68|\n",
      "|          Golddex|4340.32|\n",
      "|          Conecom|4242.85|\n",
      "| Stark Industries|4221.65|\n",
      "|         Scotfind|3911.27|\n",
      "|         Ron-tech|3805.02|\n",
      "|         Gogozoom| 3577.1|\n",
      "|       Bioholding| 3321.9|\n",
      "|         Zumgoity| 3264.4|\n",
      "|Wayne Enterprises|3193.45|\n",
      "|         Dontechi|2990.17|\n",
      "|       Gekko & Co|2934.79|\n",
      "|       Zathunicon|2913.82|\n",
      "|         Labdrill|2913.26|\n",
      "+-----------------+-------+\n",
      "only showing top 20 rows\n",
      "\n",
      "97\n",
      "+----------+-------+\n",
      "|   account|revenue|\n",
      "+----------+-------+\n",
      "|Stanredtax|  14.79|\n",
      "|Fasehatice|   19.2|\n",
      "|  Kan-code|  22.63|\n",
      "| Treequote|   73.1|\n",
      "| Konmatfix|  82.96|\n",
      "+----------+-------+\n",
      "only showing top 5 rows\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "result_prob7 = df_accounts.orderBy(\"revenue\",ascending=False).select(\"account\",\"revenue\")\n",
    "result_prob7.show(20)\n",
    "print (result_prob7.count())\n",
    "#generating id incrementally for accounts sorted by revenue in decreasing order\n",
    "result_prob7 = result_prob7.withColumn(\"index\", monotonically_increasing_id())\n",
    "#sorting by index in descending order so that we get accounts with least revenue (bottom 5)\n",
    "result_prob7.orderBy(desc(\"index\")).drop(\"index\").show(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 8: Display 'Month of Year' vs 'Sales', for GTXBasic. NOTE: \"Month of Year\" means month year (eg. Jan) and \"Month\" means month (eg. Jan 2020, Jan 2021 etc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------+-----------+--------+----------+----------+-------------+\n",
      "|opportunity_id| deal_stage| product|created_on|close_date|Month Of year|\n",
      "+--------------+-----------+--------+----------+----------+-------------+\n",
      "|      67HY0MW7|        Won|GTXBasic|2017-04-24|2017-05-06|     Apr 2017|\n",
      "|      BRL1KVVH|       Lost|GTXBasic|2017-05-19|2017-08-03|     May 2017|\n",
      "|      R22O68FF|        Won|GTXBasic|2017-03-21|2017-06-27|     Mar 2017|\n",
      "|      TMJ0OJ0B|        Won|GTXBasic|2017-06-30|2017-07-10|     Jun 2017|\n",
      "|      B22V5Z3B|       Lost|GTXBasic|2017-07-25|2017-08-07|     Jul 2017|\n",
      "|      H7ZQUWDJ|        Won|GTXBasic|2017-12-21|2017-12-30|     Dec 2017|\n",
      "|      HC77MZU1|       Lost|GTXBasic|2017-07-25|2017-09-07|     Jul 2017|\n",
      "|      27QUC5M7|In_Progress|GTXBasic|2017-11-01|      null|     Nov 2017|\n",
      "|      N3DXP5OP|In_Progress|GTXBasic|2017-02-05|      null|     Feb 2017|\n",
      "|      ZLLF7UHU|       Lost|GTXBasic|2017-09-20|2017-12-08|     Sep 2017|\n",
      "|      QRYFOK47|        Won|GTXBasic|2017-03-27|2017-05-02|     Mar 2017|\n",
      "|      QCA1IIKF|In_Progress|GTXBasic|2016-11-25|      null|     Nov 2016|\n",
      "|      P0I0DTBJ|       Lost|GTXBasic|2017-02-15|2017-04-04|     Feb 2017|\n",
      "|      5S5DO3QC|       Lost|GTXBasic|2017-01-08|2017-04-03|     Jan 2017|\n",
      "|      8QSPOR0V|       Lost|GTXBasic|2017-08-09|2017-09-12|     Aug 2017|\n",
      "|      WHRDPR4H|        Won|GTXBasic|2017-10-19|2017-10-31|     Oct 2017|\n",
      "|      V34SNG4P|In_Progress|GTXBasic|2017-10-04|      null|     Oct 2017|\n",
      "|      DNTUK4O1|In_Progress|GTXBasic|2017-05-21|      null|     May 2017|\n",
      "|      77VRR78O|       Lost|GTXBasic|2017-06-21|2017-09-06|     Jun 2017|\n",
      "|      E9JHZR7J|        Won|GTXBasic|2017-10-27|2017-12-16|     Oct 2017|\n",
      "|      9L5HPLM6|        Won|GTXBasic|2017-06-22|2017-10-02|     Jun 2017|\n",
      "|      OL2RFQCM|        Won|GTXBasic|2017-06-20|2017-08-16|     Jun 2017|\n",
      "|      377G0K33|       Lost|GTXBasic|2017-10-23|2017-10-25|     Oct 2017|\n",
      "|      Y131Y9KM|In_Progress|GTXBasic|2017-03-10|      null|     Mar 2017|\n",
      "|      NEJZ68R1|       Lost|GTXBasic|2017-07-02|2017-07-07|     Jul 2017|\n",
      "|      FOSIPD0U|In_Progress|GTXBasic|2017-09-17|      null|     Sep 2017|\n",
      "|      JYYU4CDI|In_Progress|GTXBasic|2017-06-25|      null|     Jun 2017|\n",
      "|      6RNOFZRB|In_Progress|GTXBasic|2017-10-21|      null|     Oct 2017|\n",
      "|      NFNYO1WJ|        Won|GTXBasic|2017-08-07|2017-09-11|     Aug 2017|\n",
      "|      BQ91O7T3|        Won|GTXBasic|2017-05-13|2017-07-03|     May 2017|\n",
      "+--------------+-----------+--------+----------+----------+-------------+\n",
      "only showing top 30 rows\n",
      "\n",
      "3062\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "#formatting created_on (sales initiation date)\n",
    "result_prob8 = df_sales_pipeline.filter(col(\"product\")=='GTXBasic')\\\n",
    "                                .select(\"opportunity_id\",\"deal_stage\",\"product\",\"created_on\",\"close_date\")\\\n",
    "                                .withColumn(\"Month Of year\",date_format(\"created_on\",\"LLL y\"))\n",
    "result_prob8.show(30)\n",
    "print (result_prob8.count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 9: Which sales agent(s) never lost a deal. Display as a dictionary {sales agent:sales}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['Donn Cantrell', 'James Ascencio', 'Niesha Huffines', 'Kami Bicknell', 'Versie Hillebrand', 'Kary Hendrixson', 'Anna Snelling', 'Vicki Laflamme', 'Darcel Schlecht', 'Marty Freudenburg', 'Lajuana Vencill', 'Reed Clapper', 'Elease Gluck', 'Rosie Papadopoulos', 'Jonathan Berthelot', 'Zane Levy', 'Rosalina Dieter', 'Cecily Lampkin', 'Gladys Colclough', 'Daniell Hammack', 'Moses Frase', 'Wilburn Farren', 'Violet Mclelland', 'Markita Hansen', 'Corliss Cosme', 'Cassey Cress', 'Boris Faz', 'Maureen Marcano', 'Hayden Neloms', 'Garret Kinder'])\n",
      "30\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "df_sales_notlost = df_sales_pipeline.filter(col(\"deal_stage\") != \"Lost\").select(\"opportunity_id\",\"sales_agent\",\"close_value\")\n",
    "result_prob9 = defaultdict(list)\n",
    "for row in df_sales_notlost.toJSON().collect():\n",
    "    row_json = json.loads(row)\n",
    "    if \"close_value\" in row_json:\n",
    "        result_prob9[row_json['sales_agent']].append({\"opportunity_id\":row_json['opportunity_id'],\n",
    "                                                      \"close_value\":row_json[\"close_value\"]})\n",
    "    else:\n",
    "        result_prob9[row_json['sales_agent']].append({\"opportunity_id\":row_json['opportunity_id'],\n",
    "                                                      \"close_value\":None})\n",
    "print (result_prob9.keys())\n",
    "print (len(result_prob9.keys()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 10: Display 'Sales Agents', 'Product', and 'Sales', for those sales agents who closed more than one deal on same day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------+-----------------+------------+----------------+\n",
      "|opportunity_id|      sales_agent|     product|DaysTakenToClose|\n",
      "+--------------+-----------------+------------+----------------+\n",
      "|      67HY0MW7|    Donn Cantrell|    GTXBasic|              12|\n",
      "|      R22O68FF|  Niesha Huffines|    GTXBasic|              98|\n",
      "|      J78AK31N|    Kami Bicknell|      MGRPFU|              81|\n",
      "|      8I9PRPGN|Versie Hillebrand|      MGRPFS|              41|\n",
      "|      4VHUTHOJ|    Kami Bicknell|GTXPlusBasic|               1|\n",
      "|      TMJ0OJ0B|  Kary Hendrixson|    GTXBasic|              10|\n",
      "|      MD4PBMNN|    Anna Snelling|      MGRPFU|              95|\n",
      "|      1XPVT5AY|  Kary Hendrixson|  GTXPlusPro|              57|\n",
      "|      IH2QISS9|  Kary Hendrixson|      GTXPro|              94|\n",
      "|      7JJ73XCX|   James Ascencio|GTXPlusBasic|              61|\n",
      "|      T8QRTV6F|   James Ascencio|  GTXPlusPro|              10|\n",
      "|      C7NFUAR6|Marty Freudenburg|GTXPlusBasic|              65|\n",
      "|      NXRZZBVS|  Lajuana Vencill|      MGRPFU|              52|\n",
      "|      H7ZQUWDJ|     Reed Clapper|    GTXBasic|               9|\n",
      "|      YV47EGIC|    Anna Snelling|      MGRPFS|              65|\n",
      "|      SC4LUMPZ|     Elease Gluck|      MGRPFS|              53|\n",
      "|      ZES3NR0F|Versie Hillebrand|      MGRPFS|              89|\n",
      "|      KJ1JOOQ0|  Niesha Huffines|      MGRPFS|              13|\n",
      "|      ZHV68QKO|     Reed Clapper|      GTXPro|              89|\n",
      "|      4RE1ST7V|    Kami Bicknell|  GTXPlusPro|              22|\n",
      "+--------------+-----------------+------------+----------------+\n",
      "only showing top 20 rows\n",
      "\n",
      "6438\n",
      "+------------------+------------+-----------------------+\n",
      "|       sales_agent|     product|completed_opportunities|\n",
      "+------------------+------------+-----------------------+\n",
      "|    Markita Hansen|GTXPlusBasic|                      2|\n",
      "|   Darcel Schlecht|      GTXPro|                      2|\n",
      "| Marty Freudenburg|    GTXBasic|                      2|\n",
      "|     Kami Bicknell|GTXPlusBasic|                      2|\n",
      "|  Gladys Colclough|GTXPlusBasic|                      2|\n",
      "|   Darcel Schlecht|      MGRPFS|                      2|\n",
      "|   Darcel Schlecht|GTXPlusBasic|                      2|\n",
      "|Jonathan Berthelot|    GTXBasic|                      6|\n",
      "|       Moses Frase|    GTXBasic|                      2|\n",
      "|     Kami Bicknell|    GTXBasic|                      2|\n",
      "|      Cassey Cress|    GTXBasic|                      2|\n",
      "|Rosie Papadopoulos|    GTXBasic|                      2|\n",
      "|     Anna Snelling|  GTXPlusPro|                      3|\n",
      "|   Kary Hendrixson|    GTXBasic|                      2|\n",
      "+------------------+------------+-----------------------+\n",
      "\n",
      "14\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "result_prob10 = df_sales_pipeline.filter(col(\"deal_stage\")==\"Won\")\\\n",
    "                                 .withColumn(\"DaysTakenToClose\", \n",
    "                                            datediff(to_date(\"close_date\",\"yyyy-MM-dd\"),\n",
    "                                                     to_date(\"created_on\",\"yyyy-MM-dd\")))\\\n",
    "                                 .select(\"opportunity_id\",\"sales_agent\",\"product\",\"DaysTakenToClose\")\n",
    "\n",
    "result_prob10.show(20)\n",
    "print (result_prob10.count())\n",
    "result_prob10 = result_prob10.filter(col(\"DaysTakenToClose\") == 1)\\\n",
    "                             .select(\"sales_agent\",\"product\",\"opportunity_id\")\\\n",
    "                             .groupBy(\"sales_agent\",\"product\").agg(count(\"opportunity_id\").alias(\"completed_opportunities\"))\\\n",
    "                             .filter(col(\"completed_opportunities\") > 1)\n",
    "\n",
    "result_prob10.show(20)\n",
    "print (result_prob10.count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Refer & Use Orchestra.json to answer problem 11-13 below"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 11: Display the instrument played by Lehmann Caroline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+--------------------+--------------------+---------+-------+--------------------+\n",
      "|            concerts|                  id|           orchestra|programID| season|               works|\n",
      "+--------------------+--------------------+--------------------+---------+-------+--------------------+\n",
      "|[{1842-12-07T05:0...|00646b9f-fec7-4ff...|New York Philharm...|     3853|1842-43|[{52446*, Beethov...|\n",
      "|[{1843-02-18T05:0...|1118e84e-eb59-46c...|New York Philharm...|     5178|1842-43|[{52437*, Beethov...|\n",
      "|[{1843-04-07T05:0...|08536612-27c3-437...|Musicians from th...|    10785|1842-43|[{52364*1, Beetho...|\n",
      "|[{1843-04-22T05:0...|81a3b8de-1737-4c9...|New York Philharm...|     5887|1842-43|[{52434*, Beethov...|\n",
      "|[{1843-11-18T05:0...|09581bb7-8855-496...|New York Philharm...|      305|1843-44|[{52453*, Beethov...|\n",
      "|[{1844-01-13T05:0...|0848266c-8eee-48a...|New York Philharm...|     3368|1843-44|[{51668*, Mozart,...|\n",
      "|[{1844-03-16T05:0...|8025e763-9c12-415...|New York Philharm...|     4226|1843-44|[{3707*, Spohr,  ...|\n",
      "|[{1844-05-18T05:0...|19d44866-ee7b-48d...|New York Philharm...|     5087|1843-44|[{52446*, Beethov...|\n",
      "|[{1844-11-16T05:0...|4f13ab38-9eb4-414...|New York Philharm...|     6310|1844-45|[{52456*, Beethov...|\n",
      "|[{1845-01-11T05:0...|7725e2f7-7f77-41d...|New York Philharm...|     1979|1844-45|[{51727*, Haydn, ...|\n",
      "|[{1845-03-01T05:0...|f1de3488-6831-408...|New York Philharm...|     2821|1844-45|[{52437*, Beethov...|\n",
      "|[{1845-04-19T05:0...|cd444e18-1fcd-4d6...|New York Philharm...|     3259|1844-45|[{52453*, Beethov...|\n",
      "|[{1845-11-22T05:0...|51ee4702-8f57-4fe...|New York Philharm...|     4919|1845-46|[{52575*, Mendels...|\n",
      "|[{1846-01-17T05:0...|1b162182-4605-4cb...|New York Philharm...|      562|1845-46|[{52446*, Beethov...|\n",
      "|[{1846-03-07T05:0...|66cc492e-e6eb-42e...|New York Philharm...|     1408|1845-46|[{3826*, Kalliwod...|\n",
      "|[{1846-04-25T05:0...|08205151-c17b-4de...|New York Philharm...|     1851|1845-46|[{51664*, Mozart,...|\n",
      "|[{1846-05-20T05:0...|079d4d73-e2e7-4c8...|New York Philharm...|     2321|1845-46|[{6709*16, Weber,...|\n",
      "|[{1846-11-21T05:0...|f679abf1-6beb-408...|New York Philharm...|     3540|1846-47|[{3864*, Spohr,  ...|\n",
      "|[{1847-01-09T05:0...|111c22e5-0527-4e1...|New York Philharm...|     6573|1846-47|[{51658*, Mozart,...|\n",
      "|[{1847-03-06T05:0...|07ffca52-b177-43c...|New York Philharm...|       47|1846-47|[{52453*, Beethov...|\n",
      "+--------------------+--------------------+--------------------+---------+-------+--------------------+\n",
      "only showing top 20 rows\n",
      "\n",
      "1033\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "#Edited the orchestra.json file to retrieve the proper JSON structure to accommodate Array of JSON objects\n",
    "df_orchestra = spark.read.format(\"json\").option(\"multiline\",\"true\").load(\"data/Orchestra.json\")\n",
    "df_orchestra.show(20)\n",
    "print (df_orchestra.count())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('concerts',\n",
       "  'array<struct<Date:string,Location:string,Time:string,Venue:string,eventType:string>>'),\n",
       " ('id', 'string'),\n",
       " ('orchestra', 'string'),\n",
       " ('programID', 'string'),\n",
       " ('season', 'string'),\n",
       " ('works',\n",
       "  'array<struct<ID:string,composerName:string,conductorName:string,interval:string,movement:string,soloists:array<struct<soloistInstrument:string,soloistName:string,soloistRoles:string>>,workTitle:string>>')]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orchestra.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getRequiredInstrument(ws,soloist_name):\n",
    "    exists = None\n",
    "    for work in ws:\n",
    "        if len(work['soloists']) > 0:\n",
    "            for soloist_element in work['soloists']:\n",
    "                if soloist_element[\"soloistName\"] == soloist_name:\n",
    "                    exists = 1\n",
    "                    break\n",
    "            if exists == 1:\n",
    "                break\n",
    "        else:\n",
    "            continue\n",
    "    if exists:\n",
    "        return soloist_element[\"soloistInstrument\"]\n",
    "    else:\n",
    "        return \"\"\n",
    "\n",
    "instrumentUDF = udf(lambda colname,sname: getRequiredInstrument(colname,sname))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+--------------------+--------------------+---------+-----------------+\n",
      "|                  id|           orchestra|               works|programID|return_instrument|\n",
      "+--------------------+--------------------+--------------------+---------+-----------------+\n",
      "|21b49b4a-1805-41b...|New York Philharm...|[{52437*, Beethov...|     5792|          Soprano|\n",
      "|89c1db0d-8c41-476...|New York Philharm...|[{52577*, Mendels...|     2149|          Soprano|\n",
      "|4e81347f-898d-48b...|New York Philharm...|[{52374*1, Cherub...|     6613|          Soprano|\n",
      "+--------------------+--------------------+--------------------+---------+-----------------+\n",
      "\n"
     ]
    }
   ],
   "source": [
    "test = df_orchestra.withColumn(\"return_instrument\",instrumentUDF(\"works\",lit(\"Lehmann, Caroline\")))\n",
    "test.select(\"id\",\"orchestra\",\"works\",\"programID\",\"return_instrument\").filter(col(\"return_instrument\")!=\"\").show(40)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 12: Display all vocalists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Row(composerName=['Beethoven,  Ludwig  van', 'Weber,  Carl  Maria Von', 'Hummel,  Johann', 'Pacini,  Giovanni', 'Romberg,  Bernhard', 'Onslow,  George', 'Onslow,  George', 'Rossini,  Gioachino', 'Thalberg,  Sigismond', 'Mozart,  Wolfgang  Amadeus', 'Herz,  Henri', 'Lindpaintner,  Peter  Von']),\n",
       " Row(composerName=['Beethoven,  Ludwig  van', 'Vieuxtemps,  Henri', 'Mendelssohn,  Felix', 'Donizetti,  Gaetano', 'Weber,  Carl  Maria Von']),\n",
       " Row(composerName=['Beethoven,  Ludwig  van', None, 'Loder,  George, Jr.', 'Mendelssohn,  Felix', 'Lindpaintner,  Peter  Von', 'Beriot,  Charles-Auguste  de', 'Reissiger,  Karl  Gottlieb']),\n",
       " Row(composerName=['Schumann,  Robert', 'Haydn,  Franz  Joseph', 'Ernst,  Heinrich  Wilhelm', None, 'Rietz,  Julius', 'Weber,  Carl  Maria Von', 'Mollenhauer,  Friedrich', None, 'Beethoven,  Ludwig  van']),\n",
       " Row(composerName=['Strauss,  Richard', 'Beethoven,  Ludwig  van', None, 'Volkmann,  Friedrich  Robert', 'Schumann,  Robert']),\n",
       " Row(composerName=['Wagner,  Richard', 'Rubinstein,  Anton', 'Joachim,  Joseph', None, 'Beethoven,  Ludwig  van']),\n",
       " Row(composerName=['Wagner,  Richard', 'Wagner,  Richard', 'Schubert,  Franz', None, 'Tchaikovsky,  Pyotr  Ilyich']),\n",
       " Row(composerName=['Wagner,  Richard', 'Godard,  Benjamin', 'Svendsen,  Johan', 'Beethoven,  Ludwig  van', 'Beethoven,  Ludwig  van', 'Delibes,  Léo', 'Delibes,  Léo', None, 'Beethoven,  Ludwig  van', 'Wagner,  Richard', 'Arditi,  Luigi', 'Schenck,  Elliott', 'Schenck,  Elliott', 'Ziehrer,  Carl  Michael']),\n",
       " Row(composerName=['Bulow,  Hans  Von', 'Brahms,  Johannes', 'Verdi,  Giuseppe', 'Verdi,  Giuseppe', 'Liszt,  Franz', 'Pfeffer,  Walter', None, 'Beethoven,  Ludwig  van']),\n",
       " Row(composerName=['Schumann,  Robert', 'Saint-Saens [Saint-Saëns],  Camille', None, 'Wagner,  Richard', 'Wagner,  Richard', 'Wagner,  Richard', 'Wagner,  Richard', 'Beethoven,  Ludwig  van'])]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#solution code here\n",
    "df_orchestra.select(\"works.composerName\").distinct().take(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 13: Display orchestra played under program id 2561"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+---------+--------------------+\n",
      "|programID|           orchestra|\n",
      "+---------+--------------------+\n",
      "|     2561|New York Philharm...|\n",
      "+---------+--------------------+\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#solution code here\n",
    "df_orchestra.select(\"programID\",\"orchestra\").filter(col(\"programID\")==\"2561\").show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Refer & Use Orchestra.xml to answer problem 14-15 below"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 14: Display locations used for event at time 8:15 PM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "#solution code here\n",
    "def get_locations(concerts,time):\n",
    "    locations = []\n",
    "    if len(concerts) > 0:\n",
    "        for concert in concerts:\n",
    "            if concert['Time'] == '8:15PM':\n",
    "                locations.append(concert['Location'])\n",
    "    if len(locations) > 0:\n",
    "        return locations\n",
    "    else:\n",
    "        return \"\"\n",
    "\n",
    "locationsUDF = udf(lambda colname,sname: get_locations(colname,sname))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+--------------------+--------------------+---------+---------------+\n",
      "|                  id|           orchestra|            concerts|programID|return_location|\n",
      "+--------------------+--------------------+--------------------+---------+---------------+\n",
      "|1124c816-f97c-4cf...|   New York Symphony|[{1888-12-28T05:0...|    11610|[Manhattan, NY]|\n",
      "|7e1d590a-9750-4e0...|   New York Symphony|[{1889-12-13T05:0...|     7921|[Manhattan, NY]|\n",
      "|ebe38ed5-af8a-42c...|   New York Symphony|[{1890-01-31T05:0...|     8072|[Manhattan, NY]|\n",
      "|fa51a57c-f27c-430...|   New York Symphony|[{1891-11-17T05:0...|    14304|[Manhattan, NY]|\n",
      "|20df0162-d9ad-407...|   New York Symphony|[{1891-11-19T05:0...|    14305|[Manhattan, NY]|\n",
      "|c5f00d41-3ae7-499...|   New York Symphony|[{1892-01-15T05:0...|     8087|[Manhattan, NY]|\n",
      "|de6b31a7-d117-47e...|   New York Symphony|[{1892-02-05T05:0...|     8088|[Manhattan, NY]|\n",
      "|637c6a11-0e03-48c...|   New York Symphony|[{1892-03-04T05:0...|     8089|[Manhattan, NY]|\n",
      "|d617e80c-a31a-415...|   New York Symphony|[{1892-04-01T05:0...|     8090|[Manhattan, NY]|\n",
      "|d37f0df9-9e87-477...|Members of NY Phi...|[{1892-10-21T05:0...|     9742|[Manhattan, NY]|\n",
      "|58aa553d-b941-4b9...|   New York Symphony|[{1892-11-11T05:0...|     8091|[Manhattan, NY]|\n",
      "|55d5fc26-abb2-409...|   New York Symphony|[{1892-12-02T05:0...|     8092|[Manhattan, NY]|\n",
      "|384caf29-6ebc-40b...|New York Philharm...|[{1892-12-16T05:0...|     6073|[Manhattan, NY]|\n",
      "|2678ff7b-ecfa-4c7...|   New York Symphony|[{1893-01-06T05:0...|     8093|[Manhattan, NY]|\n",
      "|43599c50-2a7d-40d...|New York Philharm...|[{1893-01-13T05:0...|     2391|[Manhattan, NY]|\n",
      "|e39ec35e-ab4e-41f...|   New York Symphony|[{1893-02-03T05:0...|     8104|[Manhattan, NY]|\n",
      "|9786f71d-9e46-405...|New York Philharm...|[{1893-02-10T05:0...|     6730|[Manhattan, NY]|\n",
      "|61de5748-841a-428...|New York Philharm...|[{1893-03-03T05:0...|     3710|[Manhattan, NY]|\n",
      "|a9501082-5d8e-449...|   New York Symphony|[{1893-03-10T05:0...|     8105|[Manhattan, NY]|\n",
      "|66cd0517-a1d9-4b1...|New York Philharm...|[{1893-03-24T05:0...|     3714|[Manhattan, NY]|\n",
      "|a8f7f5ce-cb62-4db...|   New York Symphony|[{1893-11-10T05:0...|     8107|[Manhattan, NY]|\n",
      "|0c851376-a2b2-4a7...|New York Philharm...|[{1893-11-17T05:0...|     2589|[Manhattan, NY]|\n",
      "|e02e6ffd-4071-451...|   New York Symphony|[{1893-11-19T05:0...|     9741|[Manhattan, NY]|\n",
      "|f61c75a0-7355-4a2...|   New York Symphony|[{1893-12-08T05:0...|     8108|[Manhattan, NY]|\n",
      "|489b901d-bd34-40c...|New York Philharm...|[{1893-12-15T05:0...|     6924|[Manhattan, NY]|\n",
      "|324d6827-eabb-41e...|   New York Symphony|[{1894-01-05T05:0...|     8109|[Manhattan, NY]|\n",
      "|50fcb7b0-f8e7-407...|New York Philharm...|[{1894-01-12T05:0...|     3280|[Manhattan, NY]|\n",
      "|f439468c-ee5b-43a...|New York Philharm...|[{1894-02-09T05:0...|      252|[Manhattan, NY]|\n",
      "|d16b069c-3509-454...|New York Philharm...|[{1894-03-09T05:0...|     4619|[Manhattan, NY]|\n",
      "|3bbe1795-301b-4a3...|   New York Symphony|[{1894-03-16T05:0...|     8112|[Manhattan, NY]|\n",
      "|c5ccb40c-2863-4c2...|New York Philharm...|[{1894-04-06T05:0...|     1598|[Manhattan, NY]|\n",
      "|f5c265a2-e66d-4a0...|   New York Symphony|[{1894-11-09T05:0...|     8113|[Manhattan, NY]|\n",
      "|4dba2644-4271-43e...|New York Philharm...|[{1894-11-16T05:0...|     3497|[Manhattan, NY]|\n",
      "|3e41efc1-0f56-494...|   New York Symphony|[{1894-12-07T05:0...|     8114|[Manhattan, NY]|\n",
      "|6ad4c55c-ec61-41a...|New York Philharm...|[{1894-12-14T05:0...|      435|[Manhattan, NY]|\n",
      "|eb3ed63a-6b27-449...|   New York Symphony|[{1894-12-29T05:0...|    11624|[Manhattan, NY]|\n",
      "|6587d4bd-e471-4c3...|   New York Symphony|[{1895-01-04T05:0...|     8115|[Manhattan, NY]|\n",
      "|2fadbd45-5e46-482...|   New York Symphony|[{1895-01-06T05:0...|    10576|[Manhattan, NY]|\n",
      "|eb47e326-1219-466...|New York Philharm...|[{1895-01-11T05:0...|     4191|[Manhattan, NY]|\n",
      "|a51c295b-e56d-4a3...|   New York Symphony|[{1895-02-01T05:0...|     8118|[Manhattan, NY]|\n",
      "+--------------------+--------------------+--------------------+---------+---------------+\n",
      "only showing top 40 rows\n",
      "\n"
     ]
    }
   ],
   "source": [
    "test = df_orchestra.withColumn(\"return_location\",locationsUDF(\"concerts\",lit(\"8:15PM\")))\n",
    "test.select(\"id\",\"orchestra\",\"concerts\",\"programID\",\"return_location\").filter(col(\"return_location\")!=\"\").show(40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+\n",
      "|     return_location|\n",
      "+--------------------+\n",
      "|   [Springfield, MA]|\n",
      "|        [Newark, NJ]|\n",
      "|     [Manhattan, NY]|\n",
      "|    [Providence, RI]|\n",
      "|  [Indianapolis, IN]|\n",
      "|     [New Haven, CT]|\n",
      "|      [Brooklyn, NY]|\n",
      "|  [Philadelphia, PA]|\n",
      "|      [Hartford, CT]|\n",
      "|[Manhattan, NY, B...|\n",
      "|[Manhattan, NY, M...|\n",
      "+--------------------+\n",
      "\n"
     ]
    }
   ],
   "source": [
    "test.filter(col(\"return_location\")!=\"\").select(\"return_location\").distinct().show(40)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PROBLEM 15: Display total number of programs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1033"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#solution code here\n",
    "df_orchestra.count()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "********************************************* Test ends here **************************************************"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}


================================================
FILE: Byndr/README.md
================================================
# Interview Experience for Data Engineer (Big Data) - 2021:  
### First Round:  
+ What is Hive?  
+ What is Hive metastore?  
+ Hive external table vs managed table.  
+ evalute Programming skills - one question on that.  
+ mappers and reducers in Spark execution flow.  
+ what are `groupByKey` and `reduceByKey` operations in Spark.  
+ 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.  
+ 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?
+ Questions on SQL for window functions in spark (SQL query is preferred compared to Dataframes API).  
+ Different storage formats in big data space? questions on that (`parquet`, `CSV`, `JSON`, `avro`, `delta` etc).  
+ Questions on Hadoop ecosystem if any.  


================================================
FILE: CloudCover/README.md
================================================
# Personal Experience for Data Engineer - 2021:  
## First round:  
Live Programming round - Given 1.5 hrs of time, you need to solve a problem statement live on web based IDE.  
  
## Second round:  
Techical Discussion on the projects done, Some interview questions on Spark,Hive,Hadoop:  
   - About windows functions in spark, what they are used for in spark?
   - About UDFs in spark and how they are different from normal spark functions in performance.  
   - Difference between external table and managed table in hive.  
   - experience on moving large scale data between different sinks? cloud migrations? database migrations?  
   - experience writing complex sql queries?  
   - behaviorial questions.  
   - current project and what are the responsibilities of your role specifically in your company.  
   - some other questions on bigdata, which I don't remember right now 😁  


================================================
FILE: DATFreightAnalytics/README.md
================================================
## Interview Process for Machine Learning Engineer (Personal Experience)  
1. Resume Screening.
2. Technical Assessment (Take Home Assignment).
   - Questions are mostly around MLOps concepts, Machine Learning Engineering and Designing systems.
3. Technical Round as a followup and questions.
4. Hiring Manager Round.
5. Leadership interview round.
6. Final - HR Interview covering cultural and behavioral aspects.


================================================
FILE: Facebook/ImplementSTRSTR.py
================================================
{
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        s,p =input().strip().split()
        print(strstr(s,p))

}
''' This is a function problem.You only need to complete the function given below '''
'''
	Your task is to return the index of the pattern
	present in the given string.
	
	Function Arguments: s (given text), p(given pattern)
	Return Type: Integer.
	
'''
def strstr(s,p):
    #code here
    import re
    loc = re.search(p,s)
    if loc is not None:
        return (loc.start())
    else:
        return -1

================================================
FILE: FactSet/convertArrayToWave.py
================================================
{
#Initial Template for Python 3
import math
def main():
    
    T=int(input())
    
    while(T>0):
        
        
        N=int(input())
        
        A=[int(x) for x in input().split()]
        convertToWave(A,N)
        for i in A:
            print(i,end=" ")
        
        
        print()
        
       
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function
def convertToWave(A,N):
    #Your code here
    temp=0
    for i in range(N-1):
        if i%2 == 0:
            if A[i] < A[i+1]:
                temp=A[i]
                A[i]=A[i+1]
                A[i+1]=temp
            else:
                continue
        else:
            if A[i] > A[i+1]:
                temp=A[i]
                A[i]=A[i+1]
                A[i+1]=temp
            else:
                continue

================================================
FILE: Flipkart/addTwoNumbers_LinkedListRep.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
# prints the elements of linked list starting with head
def printList(head):
    if head is None:
        print(' ')
        return
    curr_node = head
    while curr_node:
        print(curr_node.data,end=" ")
        curr_node=curr_node.next
    print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n_a = int(input())
        a = LinkedList() # create a new linked list 'a'.
        nodes_a = list(map(int, input().strip().split()))
        nodes_a = nodes_a[::-1] # reverse the input array
        for x in nodes_a:
            a.append(x)  # add to the end of the list
        n_b =int(input())
        b = LinkedList()  # create a new linked list 'b'.
        nodes_b = list(map(int, input().strip().split()))
        nodes_b = nodes_b[::-1]  # reverse the input array
        for x in nodes_b:
            b.append(x)  # add to the end of the list
        result_head = addBoth(a.head,b.head)
        printList(result_head)
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Function to add two numbers represented 
	in the form of the linked list.
	
	Function Arguments: head_a and head_b (heads of both the linked lists)
	Return Type: head of the resultant linked list.
    
    __>IMP : numbers are represented in reverse in the linked list.
    Ex:
        145 is represented as  5->4->1.
    
    resultant head is expected in the same format.
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
'''
def addBoth(head_a,head_b):
    #code here
    result = LinkedList()
    num1 = ""
    curr_node = head_a
    while curr_node != None:
        num1 += str(curr_node.data)
        curr_node = curr_node.next
    num1 = num1[::-1]
    num2 = ""
    curr_node = head_b
    while curr_node != None:
        num2 += str(curr_node.data)
        curr_node = curr_node.next
    num2 = num2[::-1]
    num = int(num1) + int(num2)
    num = str(num)[::-1]
    for i in num:
        result.append(i)
    return result.head

================================================
FILE: Flipkart/countOfInversionsArray.py
================================================
# GeeksForGeeks Code - Copied#
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for tt in range(t):
        n = int(input())
        a = list(map(int, input().strip().split()))
        print(Inversion_Count(a,n))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to return total number of inversions
	present in the array.
	
	Function Arguments: array a and size n
	Return Type: Integer 
'''
def Inversion_Count(arr,n):
    if a == sorted(a):
        return 0
    temp_arr = [0]*n
    return mergesort(arr,temp_arr,0,n-1)
    
def mergesort(arr,temp_arr,left,right):
    inv_count = 0
    if left < right:
        mid = (left + right)//2
        inv_count = mergesort(arr,temp_arr,left,mid)
        inv_count += mergesort(arr,temp_arr,mid+1,right)
        inv_count += merge(arr,temp_arr,left,mid,right)
    return inv_count
    
def merge(arr,temp_arr,left, mid, right): 
    # Merge the temp arrays back into arr[l..r] 
    i = left     # Initial index of first subarray 
    j = mid+1     # Initial index of second subarray 
    k = left     # Initial index of merged subarray 
    invcount = 0
    while i <= mid and j <= right: 
        if arr[i] <= arr[j]:
            temp_arr[k] = arr[i] 
            i += 1
        else: 
            temp_arr[k] = arr[j]
            invcount += (mid - i + 1)
            j += 1
        k += 1
    # Copy the remaining elements of L[], if there 
    # are any 
    while i <= mid: 
        temp_arr[k] = arr[i] 
        i += 1
        k += 1
    # Copy the remaining elements of R[], if there 
    # are any 
    while j <= right: 
        temp_arr[k] = arr[j] 
        j += 1
        k += 1
        
    for lr in range(left, right + 1): 
        arr[lr] = temp_arr[lr] 
    return invcount


================================================
FILE: Flipkart/parenthesisChecker.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
#Contributed by : Nagendra Jha
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    test_cases = int(input())
    for cases in range(test_cases) :
        #n = int(input())
        #n,k = map(int,imput().strip().split())
        #a = list(map(int,input().strip().split()))
        s = str(input())
        if ispar(s):
            print("balanced")
        else:
            print("not balanced")
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
Function Arguments :
		@param  : s (given string containing parenthesis) 
		@return : boolean True or False
'''

def isMatchingPair(c1,c2):
    if (c1=='(') & (c2==')'):
        return True
    elif (c1=='{') & (c2=='}'):
        return True
    elif (c1=='[') & (c2==']'):
        return True
    else:
        return False
        
def ispar(s):
    # code here
    import queue
    stack = queue.LifoQueue()
    
    for i in range(len(s)):
        if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')):
            stack.put(s[i])
        if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')):
            if stack.empty():
                return False
            elif not isMatchingPair(stack.get(),s[i]):
                return False
        
    if stack.empty():
        return True
    else:
        return False

================================================
FILE: Fractal_Analytics/Arrays.md
================================================
Given an array A of size N as an input, return the following:  
  + for every element of array, find the sum of elements upto that element(inclusive):  
  
Examples:  
```
A = [3,5,6,9,10], N = 5
for 3, sum of elements upto 3 is 0 + 1 + 2 + 3 = 6.  
for 5, sum of elements upto 5 is 0 + 1 + 2 + 3 + 4 + 5 = 15.  
for 6, sum of elements upto 6 is 0 + 1 + 2 + 3 + 4 + 5 + 6 = 21.  
for 9, sum of elements upto 9 is 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45.  
for 10, sum of elements upto 10 is 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55.  


================================================
FILE: Fractal_Analytics/Comparator.md
================================================
1. Write a comparator class with overloaded methods that perform below operations  
   - a. `compare(int a,int b)` that takes two integers `a` and `b` and returns `True` if `a == b` else `False`.  
   - b. `compare(string a,string b)` that takes two strings `a` and `b` as parameters and returns `True` if `a == b` else `False`.  
   - c. `compare(int a[],int b[])` that takes two 1-Dimensional Arrays `a` and `b` as parameters and checks the following
   conditions  
        - if length of `a` is equal to `b`.  
        - for every index `i` of a, `a[i] == b[i]`.  
   returns `True` only if above two conditions hold true otherwise returns `False`.  


================================================
FILE: Fractal_Analytics/README.md
================================================
# Interview Process for Analytics Consultant - 2019:  
### First round:  
+ Hackerrank Test (Python + SQL) or (R + SQL) test (4 python/R + 4 sql questions)(python questions are normal coding questions).  
### Second round:  
+ 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)?  

# Interview Process for Analytics Consultant - 2020:  
### First round:  
+ DoSelect Test (Python + SQL) or (R + SQL) test (4 python/R + 4 sql questions) (Python questions are not coding questions but
questions on pandas and numpy coding).  
  
# Interview Process for Senior Big Data Engineer - 2021:  
### First round:  
+ DoSelect Test (Coding Test).  
  
### Second round:  
+ 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).  
+ Focus on Spark application performance tuning techniques.  
+ In-depth SQL questions - solve using either SQL query or dataframes/datasets API in spark.  

### Third round:  
+ Interview with the Director/VP on background, questions to check if you are the right fit for the role, etc.  

### Fourth round:  
+ HR round - process improvements, challenges faced in the past etc.  


================================================
FILE: Fractal_Analytics/countChampNumbers.py
================================================
"""
find the count of champ numbers in given range [X,Y] (inclusive)
Champ numbers are numbers which have all the digits as unique
and no digit should be greater than 5

"""

def countChampNumbers(X,Y):
    count = 0
    for i in range(X,Y+1):
        if len(str(i)) == 1 and i <= 5:
            print (i)
            count += 1
        else:
            if len(set(str(i))) == len(str(i)):
                if not (('6' in str(i)) or ('7' in str(i)) or 
                        ('8' in str(i)) or ('9' in str(i))):
                    print(i)
                    count += 1
    return count
    
if __name__ == '__main__':
    T = int(input())
    for tc in range(T):
        X,Y = list(map(int, input().strip().split()))
        print (countChampNumbers(X,Y))

================================================
FILE: Fractal_Analytics/countOfAnagrams.py
================================================
"""
Given a text and a word, find the count of occurrences of anagrams
of word in given text

"""

def countAnagrams(text,word):
    count=0
    b = text
    a = word
    for i in range(len(b)-len(a)+1):
        if(sorted(a)==sorted(b[i:i+len(a)])):
            count=count+1
    return count 


if __name__ == '__main__':
    text = str(input())
    word = str(input())
    print (countAnagrams(text, word))

================================================
FILE: Fractal_Analytics/numberOfGroups.py
================================================
"""
A pole of the magnet is represented as "01" or "10"
1 = North pole and 0 = South pole
we know the like poles of magnet repel each other but unlike poles
attract.
Suppose a magnet has pole "10" and adjacent magnet also has "10" 
they attract 
if a magnet "01" is located adjacent to magnet "10" they repel.

Given a list of poles of different magnets, find the number of the
separate groups that magnets form into

example:
    number of magnets = 3
    01
    01
    10
    
    number of groups = 2 because first 2 magnets attract each other
    so will be in the same group where as the third one repels
    second one so will be in different group
"""


def numGroups(poles):
    groups = [poles[0]]
    for i in range(1,len(poles)):
        if poles[i][0] == groups[-1][0]:
            groups.append(poles[i])
        else:
            groups.append(' ')
            groups.append(poles[i])
    concat_groups = ''.join(groups)
    print (concat_groups)
    return len(concat_groups.split(' '))
    
if __name__ == '__main__':
    n = int(input())
    poles = []
    for tc in range(n):
        pole = input()
        poles.append(pole)
    print (numGroups(poles))

================================================
FILE: Fractal_Analytics/sorting_words.md
================================================
Given a sentence, sort the words of a sentence according to the their individual lengths. If one or more words have same length
then sort the words by first character of the word.

```
Example: 
Input: The quick brown fox jumps over the lazy dog
Output: dog fox the The lazy over brown jumps quick

```
+ This problem can be extended to sorting the words by second letter in case of collision with first letter and continue
till the end of word and stop when collision is resolved.  


================================================
FILE: Fractal_Analytics/substrings.md
================================================

2. Get the number of distinct substrings possible for a given string, you can use the below operations:  
  
   - a. Remove 0 or more characters from left side of the string.  
   - b. Remove 0 or more characters from right side of string.  
   - c. Remove 0 or more characters from both left and right side of string.  
     
Examples:  
```
Input  : str = “ababa”
Output : 10
Total number of distinct substring are 10, which are,
"", "a", "b", "ab", "ba", "aba", "bab", "abab", "baba"
and "ababa"
```  
```
Input : abcd
Output : abcd abc ab a bcd bc b cd c d
All Elements are Distinct
```  
```
Input : aaa
Output : aaa aa a aa a a
All elements are not Distinct
```  


================================================
FILE: Fre8wise/README.md
================================================
# Process for Software engineer role:  
## First round:  
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  

## Second round:  
1. Technical interview with one of the technical leads.  
2. Questions from the CV, work experience, challenges in projects you have undertaken.  
3. Design a queueing system that serves multiple agents looking for differnet datasets being produced from different producers/systems.  
4. Memory management in Data engineering pipelines.  
5. Questions on lambda architecture.  
6. Questions on nitty-gritty details of how you executed projects in production.  
7. Focus on system design and understanding.  


================================================
FILE: Fre8wise/manipulate_string.py
================================================
"""
Solve the following algorithm problem:
    Given a string, develop a solution that removes only 1's
    in the beginning
    
    Examples:
        1198fgh098nm -> 98fgh098nm
        a1198fgh098nm -> a1198fgh098nm
        a1198fgh098nm11 -> a1198fgh098nm11
"""

s = "1198fgh098nm"


def changeString(s):
    try:
        while (s.index("1") == 0):
            slist = list(s)
            temp = slist.pop(0)
            s = "".join(slist)
    except:
        pass
    return s

if __name__ == '__main__':
    s = input()
    print (changeString(s))

================================================
FILE: Goldman-Sachs/convertArrayToWave.py
================================================
{
#Initial Template for Python 3
import math
def main():
    
    T=int(input())
    
    while(T>0):
        
        
        N=int(input())
        
        A=[int(x) for x in input().split()]
        convertToWave(A,N)
        for i in A:
            print(i,end=" ")
        
        
        print()
        
       
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function
def convertToWave(A,N):
    #Your code here
    temp=0
    for i in range(N-1):
        if i%2 == 0:
            if A[i] < A[i+1]:
                temp=A[i]
                A[i]=A[i+1]
                A[i+1]=temp
            else:
                continue
        else:
            if A[i] > A[i+1]:
                temp=A[i]
                A[i]=A[i+1]
                A[i+1]=temp
            else:
                continue

================================================
FILE: Goldman-Sachs/numberOfSquares_in_NbyN_CheesBoard.py
================================================
def num_of_squares(n):
    if n == 1:
        return (1)
    else:
        nSquares = 0
        for I in range(1,n+1):
            nSquares = nSquares + (I*I)
        return (nSquares)
            

if __name__ == '__main__':
    T = int(input())
    for tcase in range(T):
        n = int(input())
        print (num_of_squares(n))

================================================
FILE: Goldman-Sachs/printNumbersContain123.py
================================================
def contains123(arr):
    c = {'1','2','3'}
    tracker = []
    arr = sorted(arr)
    for i in arr:
        a = set(str(i))
        if a.issubset(c):
            print (i,end=" ")
            tracker.append(1)
        else:
            tracker.append(0)
    if len(set(tracker))==1 and 0 in tracker:
        print (-1,end="")

if __name__ == '__main__':
    t = int(input())
    for tcase in range(t):
        n = int(input())
        arr = list(map(int,input().strip().split()))
        contains123(arr)
        print ('\n',end="")

================================================
FILE: Goldman-Sachs/repeatingCharacter_LeftmostOccurrence.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for i in range(t):
        s=str(input())
        index=repeatingCharacter(s)
        if(index==-1):
            print(-1)
        else:
            print(s[index])
            
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to return the lefmost index of the repeating 
	character whose first appereance is left most or return
	-1 if all characters are distinct.
	
	Function Arguments: s (given string)
	Return Type: integer
'''
def repeatingCharacter(s):
    #code here
    import collections
    freqs = collections.Counter(s)
    if len(set(freqs.values())) == 1 and 1 in set(freqs.values()):
        return -1
    else:
        inds = []
        for k,v in freqs.items():
            if v > 1:
                inds.append(s.index(k))
        return min(inds)

================================================
FILE: Google/First_Recurring_Character_In_String.py
================================================
from collections import Counter
input_string = input()

def firstRecurringChar(input_string):
    recurring_chars= []
    count_dict = Counter(input_string)
    for x, y in count_dict.items():
        if y > 1:
            recurring_chars.append(x)
    if recurring_chars:
        return recurring_chars[0]
    else:
        return (-1)
    
if __name__ == '__main__':
    print (firstRecurringChar(input_string))

================================================
FILE: Google/allocateMinimumPages.py
================================================
import math
def isValid(arr,n,k,mi):
    std = 1
    curr = 0
    for i in range(n):
        if curr + arr[i] > mi:
            curr = arr[i]
            std += 1
            if std > k:
                return False
        else:
            curr += arr[i]
    return True

def allocMinPages(arr,n,k):
    if k > n:
        return -1
    s,totalpage = 0,0
    for i in range(n):
        totalpage += arr[i]
        s = max(s,arr[i])
    e = totalpage
    finalAns = s
    while s <= e:
        mid = math.floor((s+e)/2)
        if isValid(arr,n,k,mid):
            finalAns = mid
            e = mid - 1
        else:
            s = mid + 1
    return finalAns
    
if __name__ == '__main__':
    T = int(input())
    for tcase in range(T):
        N = int(input())
        arr = list(map(int,input().strip().split()))
        M = int(input())
        print (allocMinPages(arr,N,M))

================================================
FILE: Google/checkPairsWithGivenSum.py
================================================
"""
This problem was recently asked by Google.

Given a list of numbers and a number k, return whether any two numbers from the 
list add up to k.

For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
"""


def isPairWithGivenSum(arr,n,x):
    left,right = 0,n-1
    arr = sorted(arr)
    while left < right:
        if ((arr[left] + arr[right]) < x):
            left += 1
        elif (arr[left] + arr[right] == x):
            return True
        elif (arr[left] + arr[right] > x):
            right -= 1
    return False

if __name__ == '__main__':
    T = int(input())
    for tcs in range(T):
        arr = list(map(int,input().strip().split()))
        n = len(arr)
        x = int(input())
        print (isPairWithGivenSum(arr,n,x))

================================================
FILE: Google/maxIndexDiffOfArray.py
================================================
{
#Initial Template for Python 3
import math
def main():
        T=int(input())
        while(T>0):
            
            n=int(input())
            
            arr=[int(x) for x in input().strip().split()]
            print(maxIndexDiff(arr,n))
            
            
            T-=1
if __name__ == "__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function
def maxIndexDiff(arr, n): 
    ##Your code here
    maxxDiff = 0
    for i in range(n):
        for j in range(i+1,n):
            if arr[i]<=arr[j]:
                if maxxDiff < j - i:
                    maxxDiff = j - i
    return maxxDiff

================================================
FILE: Grofers/QuickSort.py
================================================
{
#Initial Template for Python 3
if __name__ == "__main__":
    t=int(input())
    for i in range(t):
        n=int(input())
        arr=list(map(int,input().split()))
        quickSort(arr,0,n-1)
        for i in range(n):
            print(arr[i],end=" ")
        print()

}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
def quickSort(arr,low,high):
    if low < high:
 
        # pi is partitioning index, arr[p] is now
        # at right place
        pi = partition(arr,low,high)
 
        # Separately sort elements before
        # partition and after partition
        quickSort(arr, low, pi-1)
        quickSort(arr, pi+1, high)
        
def partition(arr,low,high):
    #add code here
    tmp = 0
    pivot = arr[high]
    i = low - 1
    for j in range(low,high):
        if arr[j] <= pivot:
            i += 1
            tmp = arr[i]
            arr[i] = arr[j]
            arr[j] = tmp
    tmp = arr[i+1]
    arr[i+1] = arr[high]
    arr[high] = tmp
    return i+1

================================================
FILE: Guardant-Health/README.md
================================================
# Hackerrank Test (Personal Experience)  


================================================
FILE: Guardant-Health/fallen_leaves.py
================================================
"""
Coding Test - Hackerrank

Given an array that has number of leaves on N trees (size of array = N)(arr[i]
represents number of leaves for ith tree),
percentage, array of days (can be in any order), starting and ending arrays

Scenario:
    every day from each tree, given percentage of leaves will be fallen.
    
    Task:
        There are q queries,each query has day[q].starting[q] and ending[q]
        find out for each query how many leaves are fallen in total from
        all the trees with given start and end indices.
        
    Example:
        arr = [10,20,30,20,10]
        percentage = 30
        days = [1,1,2]
        starting = [2,1,1]
        ending = [4,3,4]
        
        after first day number of fallen leaves in the given range of starting[0]
        and ending[0] is 6 + 9 + 6 = 21 (required answer)
        Remaining leaves after first day = [7,14,21,14,7]
        
In this way answer all the queries

"""

================================================
FILE: Guardant-Health/maintainMinimumStartingNumber.py
================================================
"""
Coding Test - Hackerrank

what is the minimum starting number to maintain such that the running sum will
always be atleast 1

Example: 
    arr = [3,-6,5,-2,1]
    4 is the mininum number we need to start with
    Let's check:
        4 + 3 = 7
        7 + (-6) = 1
        1 + 5 = 6
        6 + (-2) = 4
        4 + 1 = 5
        so it's 4.
        
    arr = [-4,3,-2,1]
    5 is the minimum number we need to start with
    Let's check:
        5 + (-4) = 1
        1 + 3 = 4
        4 + (-2) = 2
        2 + 1  3
        so it's 5 
"""

def minStartNumber(arr):
    bounds = []
    total = 1
    for el in arr:
        total += (-1 * el)
        bounds.append(total)
    return max(bounds)


if __name__ == '__main__':
    arr1 = [3,-6,5,-2,1]
    print (minStartNumber(arr1))
    
    arr2 = [-4,3,-2,1]
    print (minStartNumber(arr2))

================================================
FILE: HighRadius-Technologies/README.md
================================================
## Interview questions (Personal Experience):  

#### 1. Confusion matrix for any classification algorithm is showed and what are precision and recall values from the matrix?  
  
+ **What is precision**: `Number of True Positives / (Total number of Total Positives and False Positives)`  
+ **What is Recall** : `Number of True Positives / (Total Number of Total Positives and False Negatives)`  

#### 2. How do you deal with overfitting in your machine learning model?  
  
+ Regularization - (LASSO or Ridge Regression) (L1 and L2 regularization).  
+ K-Fold cross validation with variable K.  
+ Resampling of Train and Test splits of a datasets, sometimes involve out-of-time validation dataset.  
+ Dimensionality Reduction in case of many features in a dataset.  
+ Ensemble Learning.  

#### 3. How do you explain p-value to a layman? - Hypothesis testing.  

+ p-value is metric by which we decide statistically significant variables.  
+ It's a measure of how extreme an observed value is under the assumed null hypothesis: the smaller it is, the more extreme the 
observation. We can define p-value as the smallest significance level at which the null hypothesis would be rejected.  
+ As the p-value gets smaller, we start wondering if the null hypothesis really is true and well maybe we should change our minds 
(and reject the null hypothesis).  

#### 4. How do you deal with concurrent predictions from decision Trees in ensemble algorithms like random forest?
+ Do some google research on this, there are multiple techniques to deal with this.


================================================
FILE: Hike/QuickSort.py
================================================
{
#Initial Template for Python 3
if __name__ == "__main__":
    t=int(input())
    for i in range(t):
        n=int(input())
        arr=list(map(int,input().split()))
        quickSort(arr,0,n-1)
        for i in range(n):
            print(arr[i],end=" ")
        print()

}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
def quickSort(arr,low,high):
    if low < high:
 
        # pi is partitioning index, arr[p] is now
        # at right place
        pi = partition(arr,low,high)
 
        # Separately sort elements before
        # partition and after partition
        quickSort(arr, low, pi-1)
        quickSort(arr, pi+1, high)
        
def partition(arr,low,high):
    #add code here
    tmp = 0
    pivot = arr[high]
    i = low - 1
    for j in range(low,high):
        if arr[j] <= pivot:
            i += 1
            tmp = arr[i]
            arr[i] = arr[j]
            arr[j] = tmp
    tmp = arr[i+1]
    arr[i+1] = arr[high]
    arr[high] = tmp
    return i+1

================================================
FILE: IQLECT/LargestPrimeFromSubsetSum.py
================================================
# Q)Find largest possible prime number that can be generated by adding all the elements of any subset of the given array. 
# Return -1 if it is impposible.
# Implement the method largestPrime() below

# 	------------------------------
# 	Constraints:
# 	Length of array < 16
# 	Each element in array is zero or a positive integer < 10000
# 	------------------------------

# 	Example
# 		Input:
# 		[3, 3, 2, 2]

# 		Output:
# 		7


# 		Input:
# 		[0, 2, 4, 1, 2, 4, 4]

# 		Output:
# 		17


# 		Input:
# 		[6]

# 		Output:
# 		-1





# Implement this method to return the expected output

import itertools

def largestPrime(a):
    allPrimes = []
    for i in range(1,len(a)+1):
        allCombs = list(itertools.combinations(a,i))
        for j in allCombs:
            req_num = sum(j)
            if req_num == 2 | req_num == 3:
                allPrimes.append(req_num)
            isPrime = []
            if (req_num > 1) & (req_num != 2) & (req_num != 3): 
               for i in range(2, req_num//2):
                   if (req_num % i) == 0:
                       isPrime.append(0)
                       break 
                   else:
                       isPrime.append(1)
            else:
                isPrime.append(0)
            if 1 in isPrime and 0 not in isPrime:
                allPrimes.append(req_num)
    if allPrimes:
        return max(allPrimes)
    else:
        return -1
    
# No need to change below this
# No need to change below this
# No need to change below this
# No need to change below this
# No need to change below this
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
#################################################################################################################
# No need to change below this
import traceback
def testLargestPrime():
	data = [
		[3, 3, 2, 2],
		[0, 2, 4, 1, 2, 4, 4],
		[6],
		[87, 47, 33],
		[772, 312, 421, 706, 258, 583],
		[854, 964, 59, 747, 753, 511, 40, 340, 703],
		[2, 9],
		[7, 6, 5, 2, 2, 5, 0, 0],
		[36, 81, 37, 89, 36, 77, 89, 33, 36, 45],
		[0,3,49]

	]
	
	output = [7, 17, -1, 167, 1697, 4931, 11, 23, 523, 3]

	accepted = 0
	for i in range(len(data)):
		try:			
			print ("Test case: " + str(i))
			print ("Input:")
			print (str(data[i]))
			print ("Expected output:")
			print (output[i])
			print ("Actual Output:")			
			ans = largestPrime(data[i])
			print (ans)
			if(ans == output[i]):
				accepted +=1
		except:
			print(traceback.format_exc())

		print ("\n\n")

	print ("Verdict:")
	if(accepted == len(output)):
		print ("------All test passed-------")
	else:
		print ("-----Test Failed: " + str(accepted) + " tests passed out of " + str(len(output)) + "-----")	


testLargestPrime()

================================================
FILE: IQLECT/README.md
================================================
# Asked to solve these questions in-person (In office) (No platform)


================================================
FILE: InMobi/README.md
================================================
# Interview Process for Big Data Engineer 2020 (Personal):  
1. First round of interview with onshore engineering manager from U.S.A.  
2. Questions about your work experience on distributed systems, spark and data engineering pipelines.  
3. what is it that you do as a part of your daily routine at work?  
4. Tell me your understanding about hadoop?  
5. What kind of challenges did you face in your projects? and How did you resolve them?  
6. How do you handle memory leaks/failure of jobs due to memory errors?  
7. Explain your understanding of hive internal table vs external table?  
8. How did you optimize complex queries in hive?  - partitions, buckets etc  
9. How do you handle spark applications that are taking too long (certain task is leading to memory leaks)?  


================================================
FILE: Infrrd/problem01/maximumRowsWithAll1s.py
================================================
import collections

def maximumRows(binary_matrix,K):
    N = len(binary_matrix)
    M = len(binary_matrix[0])
    numOf1s = [collections.Counter(x)[1] for x in binary_matrix]
    #Number of flips <= K
    maximum1s = max(numOf1s)
    #numOfRows_Maximum1s = collections.Counter(numOf1s)[maximum1s]
    total = []
    for i in range(len(binary_matrix)):
        xyPairs1 = []
        for j in range(M):
            if binary_matrix[i][j] == 1:
                xyPairs1.append(j)
        total.append(xyPairs1)
    maximum1sRows = [k for k,v in enumerate(numOf1s) if v == maximum1s]
    #maxmimize first Row
    finalCountList = []
    for e in maximum1sRows:
        row = set(total[e])
        UniversalSet = set(range(M))
        needInc = UniversalSet-row
        checkList = sorted(list(set(range(N)) - {e}))
        a = checkList[0]
        b = checkList[len(checkList)-1]
        countList = []
        for u in total[a:b+1]:
            count = 0
            if needInc & set(u):
                count += len(needInc & set(u))
            countList.append(count)
        finalCountList.append(countList)
    return (len(finalCountList)//K)
        
        
if __name__ == '__main__':
    N,M,K = list(map(int,input().strip().split()))
    binary_matrix = []
    for I in range(N):
        row = list(map(int,input().strip().split()))
        binary_matrix.append(row)
    print (maximumRows(binary_matrix,K))

================================================
FILE: Infrrd/problem02/countMe.py
================================================
def countMe(arrA,arrL,arrR,arrX):
    resultCount = []
    for b in range(len(arrX)):
        targetX = arrX[b]
        p = arrL[b]
        q = arrR[b]
        resultCount.append(countOfNums(arrA[p-1:q],targetX))
    return (" ".join(str(i) for i in resultCount))

def countOfNums(array,target):
    C = 0
    for x in array:
        if target%x == 0:
            C += 1
    return (C)

if __name__ == '__main__':
    sizeOfA = int(input())
    arrA = list(map(int,input().strip().split()))
    numQ = int(input())
    arrL = list(map(int,input().strip().split()))
    arrR = list(map(int,input().strip().split()))
    arrX = list(map(int,input().strip().split()))
    print (countMe(arrA,arrL,arrR,arrX))
    

================================================
FILE: Instabase/Add2BinaryStrings.py
================================================
"""
Add two binary strings and get the resultant
Hint:
    Try it without converting individual entities into numerical equivalents
    
Solution:
    Refer: https://www.geeksforgeeks.org/program-to-add-two-binary-strings/
"""

================================================
FILE: Instabase/README.md
================================================
# Coding questions on Enthire (Personal Experience)


================================================
FILE: Instabase/checkPairsWithGivenSum.py
================================================
"""
Daily Coding Problem #1
This problem was recently asked by Google.

Given a list of numbers and a number k, return whether any two numbers from the 
list add up to k.

For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
"""


def isPairWithGivenSum(arr,n,x):
    left,right = 0,n-1
    arr = sorted(arr)
    while left < right:
        if ((arr[left] + arr[right]) < x):
            left += 1
        elif (arr[left] + arr[right] == x):
            return True
        elif (arr[left] + arr[right] > x):
            right -= 1
    return False

if __name__ == '__main__':
    T = int(input())
    for tcs in range(T):
        arr = list(map(int,input().strip().split()))
        n = len(arr)
        x = int(input())
        print (isPairWithGivenSum(arr,n,x))

================================================
FILE: Intuit/BuySellStock.py
================================================
{
#Initial Template for Python 3
import math
def main():
        T=int(input())
        while(T>0):
            
            n=int(input())
            
            arr=[int(x) for x in input().strip().split()]
            stockBuySell(arr,n)
            print()
            
            T-=1
if __name__ == "__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function
def stockBuySell(A,n):
    if A == sorted(A):
        print ("(" + str(0) + " " + str(n-1) + ")",end=" ")
    elif A == sorted(A,reverse=True):
        print ("No Profit",end = " ")
    else:
        local_min = []
        local_max = []
        for i,v in enumerate(A):
            if i == 0:
                if v < A[i+1]:
                    local_min.append(i)
            elif i == n-1:
                if v > A[i-1]:
                    local_max.append(i)
            else:
                if A[i-1] <= v and v >= A[i+1]:
                    local_max.append(i)
                if A[i-1] >= v and v <= A[i+1]:
                    local_min.append(i)
        if len(local_max) == len(local_min):
            for i in range(len(local_max)):
                x = " ".join([str(local_min[i]),str(local_max[i])])
                print ("("+x+")",end=" ")
        else:
            x = " ".join([str(max(local_min)),str(max(local_max))])
            print ("("+x+")",end = " ")

================================================
FILE: Intuit/binaryArraySort.py
================================================
{
#Initial Template for Python 3
import math
def main():
        T=int(input())
        while(T>0):
            N=int(input())
            A=list(map(int,input().split()))
            
            binSort(A,N)
            
            for i in A:
                print(i,end=" ")
            print()
            
            T-=1
if __name__ == "__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
##Complete this function
def binSort(arr, n): 
    #Your code here
    
    
    '''
    No need to print the array
    '''
    c0 = arr.count(0)
    c1 = arr.count(1)
    for i in range(c0):
        arr[i] = 0
    for i in range(c0,c0+c1):
        arr[i] = 1

================================================
FILE: Kritikal-Solutions/Delete_Without_Head_Pointer.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    def getNode(self,value): # return node with given value, if not present return None
        curr_node=self.head
        while(curr_node.next and curr_node.data != value):
            curr_node=curr_node.next
        if(curr_node.data==value):
            return curr_node
        else:
            return None
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n = int(input())
        a = LinkedList() # create a new linked list 'a'.
        nodes = list(map(int, input().strip().split()))
        for x in nodes:
            a.append(x)
        del_elem = int(input())
        to_delete=a.getNode(del_elem)
        deleteNode(to_delete)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
    Your task is to delete the given node from
	the linked list, without using head pointer.
	
	Function Arguments: node (given node to be deleted) 
	Return Type: None, just delete the given node from the linked list.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
	Contributed By: Nagendra Jha
'''
def deleteNode(curr_node):
    #code here
    prev = None
    curr = a.head
    while curr != None and curr_node != None:
        if curr.data == curr_node.data:
            if prev:
                prev.next = curr.next
            else:
                a.head = curr.next
            return
        prev = curr
        curr = curr.next

================================================
FILE: LeadSquared/README.md
================================================
# Coding Questions on mettl platform (Personal Experience)


================================================
FILE: LeadSquared/UniqueWaysToClimbStaircase.py
================================================
"""
This question is asked in Interview
    
There are n stairs, a person standing at the bottom wants to reach the 
top. The person can climb either 1 stair or 2 stairs at a time. Count 
the number of ways, the person can reach the top.

Example:
    number of stairs = 5
    steps allowed = 1 or 2
"""

def countWays(n,m):
    """
    Solution to above problem:
        Pros: 
            It will consider all the possible steps from 1 to given m.
        Cons:
            No control by external user (if user wants to give only certain step values
            say in the form of an array).
    """
    res = [None] * (n+1)
    temp = 0
    res[0] = 1
    for i in range(1,n+1):
        s = i - m - 1
        e = i - 1
        if s >= 0:
            temp -= res[s]
        temp += res[e]
        res[i] = temp
        print (res)
    return res[n]

if __name__ == '__main__':
    n,m = 5,2
    print (countWays(n,m))
    n,m = 5,3
    print (countWays(5,3))


def countWays1(n,args):
    """
    Solution that mitigates the cons of above solution
    Give allowed step values in the form of an array (here it is args)
    """
    m = len(args)
    count = [0 for i in range(n + 1)] 
      
    # base case 
    count[0] = 1
      
    # Count ways for all values up  
    # to 'N' and store the result 
    for i in range(1, n + 1): 
        for j in range(m): 
  
            # if i >= arr[j] then 
            # accumulate count for value 'i' as 
            # ways to form value 'i-arr[j]' 
            if (i >= args[j]): 
                count[i] += count[i - args[j]] 
      
    # required number of ways  
    return count[n] 

if __name__ == '__main__':
    print (countWays1(5,[2,3]))
    print (countWays1(5,[1,3,4]))
    print (countWays1(4,[1,3,4]))
    print (countWays1(10,[1,3,4]))
    print (countWays1(6,[3,2]))
    print (countWays1(5,[1,2,3]))
    print (countWays1(4,[1]))
    print (countWays1(4,[2]))
    print (countWays1(6,[3]))

================================================
FILE: LeadSquared/maximumSumLikeTimeCoefficients.py
================================================
"""
Coding Test - Round 1

Given an array of N integers (negative integers allowed) which say likings of
N foods by a customer

Time taken to prepare a food arr[i] is i

like-time co-efficient of food is defined as i*arr[i]. Sum of like-time
co-efficients can be obtained by doing the add up of i*arr[i]

Find the maximum sum of like-time co-efficients that can be achieved from
a given array.

Hint: Consider all combinations of likings from a given array.

Here is the idea:

"""

import itertools

def maxSumLikeTimeCoeff(arr,N):
    all_sums = []
    for r in range(1,N+1):
        combinations = set(itertools.combinations(arr,r))
        for x in combinations:
            sums = 0
            for i in range(len(x)):
                sums += (i+1) * x[i]
            all_sums.append(sums)
    return max(all_sums)

if __name__ == '__main__':
    N = int(input())
    arr = list(map(int,input().strip().split()))
    print (maxSumLikeTimeCoeff(arr,N))

================================================
FILE: LeadSquared/totalDistanceByStreetLights.py
================================================
"""
Coding Test - Round 1

Given N street lights, and an array of tuples which signify the start and 
end distances of street covered by that street light.

Find the total distance covered by all the street lights

Ex:1
    N = 1
    arr = [(5,10)]
    Number of street lights = 1
    and distance covered by street light i is 5m to 10m which is 10-5 = 5m
    
Ex:2  
    N = 2
    arr = [(5,10),(8,12)]
    Number of street lights = 2
    street light 0 = 10 - 5 = 5
    street light 1 = 12 - 8 = 4
    common region = 10 - 8 = 2
    total distance = (5 + 4 - 2) = 7
    
"""

def total_distance(intervals):
    if not intervals:
        return 0
    if len(intervals) == 1:
        return abs(intervals[0][0] - intervals[0][1])
    result = 0
    common = 0
    intervals = sorted(intervals,key=lambda x: x[0])
    for i in range(len(intervals)):
        result += abs(intervals[i][0] - intervals[i][1])
    for i in range(len(intervals)-1):
        if intervals[i][1] > intervals[i+1][0]:
            common += abs(intervals[i][1] - intervals[i+1][0])
    result = abs(result - common)
    return result

if __name__ == '__main__':
    arr1 = [(5,10)]
    print (total_distance(arr1))
    arr2 = [(5,10),(8,12)]
    print (total_distance(arr2))
    
    #subset testcase
    arr3 = [(2,9),(3,6)]
    print (total_distance(arr3))

================================================
FILE: MAQ_Software/Closet0s1s2s.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for i in range(t):
        n=int(input())
        a=list(map(int,input().strip().split()))
        segragate012(a,n)
        print(*a)
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
''' Your task to is sort the array a of 0s,1s and 2s
    of size n. You dont need to return anything.'''
def segragate012(a,n):
    #code here
    c0 = a.count(0)
    c1 = a.count(1)
    c2 = a.count(2)
    for i in range(c0):
        a[i] = 0
    for i in range(c0,c0+c1):
        a[i] = 1
    for i in range(c0+c1,c0+c1+c2):
        a[i] = 2
    #print (" ".join(str(i) for i in a),end="")

================================================
FILE: MakeMyTrip/rotateLinkedListByKelements.py
================================================
{
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
class LinkedList:
    def __init__(self):
        self.head = None
    def push(self, new_data):
        new_node = Node(new_data)
        new_node.next = self.head
        self.head = new_node
    def printList(self):
        temp = self.head
        while(temp):
            print(temp.data, end=" ")
            # arr.append(str(temp.data))
            temp = temp.next
        print("")
if __name__ == '__main__':
    start = LinkedList()
    t = int(input())
    while(t > 0):
        llist = LinkedList()
        n = int(input())
        values = list(map(int, input().strip().split()))
        for i in reversed(values):
            llist.push(i)
        k = int(input())
        new_head = rotateList(llist.head, k)
        llist.head = new_head
        llist.printList()
        t -= 1
# Contributed by: Harshit Sidhwa

}
''' This is a function problem.You only need to complete the function given below '''
# Your task is to complete this function
'''
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
'''
# This function should rotate list counter-
# clockwise by k and return new head (if changed) 
def rotateList(head, k):
    # code here
    global llist
    llist = LinkedList()
    C = 0
    curr_node = head
    part1 = []
    part2 = []
    while curr_node != None:
        if C <= k-1:
            part1.append(curr_node.data)
        elif C > k-1:
            part2.append(curr_node.data)
        C += 1
        curr_node = curr_node.next
    total = reversed(part2 + part1)
    for i in total:
        llist.push(i)
    return llist.head

================================================
FILE: MakeMyTrip/sortedLinkedList012s.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
# prints the elements of linked list starting with head
def printList(head):
    if head is None:
        print(' ')
        return
    curr_node = head
    while curr_node:
        print(curr_node.data,end=" ")
        curr_node=curr_node.next
    print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n = int(input())
        a = LinkedList() # create a new linked list 'a'.
        nodes_a = list(map(int, input().strip().split()))
        for x in nodes_a:
            a.append(x)  # add to the end of the list
        printList(segregate(a.head))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to segregate the list of 
	0s,1s and 2s.
	
	Function Arguments: head of the original list.
	Return Type: head of the new list formed.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
	Contributed By: Nagendra Jha
'''
def segregate(head):
    #code here
    global a
    a = LinkedList()
    curr_node = head
    mylist = []
    while curr_node != None:
        mylist.append(curr_node.data)
        curr_node = curr_node.next
    mylist = sorted(mylist)
    for i in mylist:
        a.append(i)
    return a.head

================================================
FILE: Mastek/README.md
================================================
Consider the below employee table where ManagerID is mapped to each EmployeeID:

Input:
| EmployeeID | EmployeeName | ManagerID |
|------------|--------------|-----------|
|    400     |    A1        |    null   |
|    401     |    A2        |    400    |
|    500     |    A3        |    401    |
|    501     |    A4        |    401    |
|    502     |    A5        |    501    |

Write the SQL query that identifies the level of each manager as mentioned in the below output:

| EmployeeID | EmployeeName | ManagerID | Level |
|------------|--------------|-----------|-------|
|   400      |   A1         |   null    |   0   |
|   401      |   A2         |   400     |   1   |
|   500      |   A3         |   401     |   2   | 
|   501      |   A4         |   401     |   2   |
|   502      |   A5         |   501     |   3   |


### Solution:
               400
                  |
              401 (depth from 400 = 1)
              /   \
          500  501 (depth from 400 = 2)
                         \
                          502 (depth from 400 = 3)

400 -> 401  
401 -> 500, 501  
501 -> 502  

**What we want to do here is use RECURSIVE CTE to traverse the tree in SQL and compute the depth at every level.**


================================================
FILE: Mastek/computedepth.sql
================================================
-- Oracle solution

WITH RecursiveCTE (lvl, ManagerID, EmployeeID) AS (
   SELECT 1 AS lvl, ManagerID, EmployeeID
   FROM employees
   WHERE ManagerID IS NULL
   UNION ALL
   SELECT lvl + 1, employees.ManagerID, employees.EmployeeID
   FROM employees
   JOIN RecursiveCTE
     ON employees.ManagerID = RecursiveCTE.EmployeeID
)
SELECT * FROM RecursiveCTE;


================================================
FILE: Microsoft/countOfInversionsArray.py
================================================
# GeeksForGeeks Code - Copied#
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for tt in range(t):
        n = int(input())
        a = list(map(int, input().strip().split()))
        print(Inversion_Count(a,n))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to return total number of inversions
	present in the array.
	
	Function Arguments: array a and size n
	Return Type: Integer 
'''
def Inversion_Count(arr,n):
    if a == sorted(a):
        return 0
    temp_arr = [0]*n
    return mergesort(arr,temp_arr,0,n-1)
    
def mergesort(arr,temp_arr,left,right):
    inv_count = 0
    if left < right:
        mid = (left + right)//2
        inv_count = mergesort(arr,temp_arr,left,mid)
        inv_count += mergesort(arr,temp_arr,mid+1,right)
        inv_count += merge(arr,temp_arr,left,mid,right)
    return inv_count
    
def merge(arr,temp_arr,left, mid, right): 
    # Merge the temp arrays back into arr[l..r] 
    i = left     # Initial index of first subarray 
    j = mid+1     # Initial index of second subarray 
    k = left     # Initial index of merged subarray 
    invcount = 0
    while i <= mid and j <= right: 
        if arr[i] <= arr[j]:
            temp_arr[k] = arr[i] 
            i += 1
        else: 
            temp_arr[k] = arr[j]
            invcount += (mid - i + 1)
            j += 1
        k += 1
    # Copy the remaining elements of L[], if there 
    # are any 
    while i <= mid: 
        temp_arr[k] = arr[i] 
        i += 1
        k += 1
    # Copy the remaining elements of R[], if there 
    # are any 
    while j <= right: 
        temp_arr[k] = arr[j] 
        j += 1
        k += 1
        
    for lr in range(left, right + 1): 
        arr[lr] = temp_arr[lr] 
    return invcount


================================================
FILE: Microsoft/merge2SortedLinkedLists.py
================================================
{
#Initial Template for Python 3
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n,m = map(int, input().strip().split())
        a = LinkedList() # create a new linked list 'a'.
        b = LinkedList() # create a new linked list 'b'.
        nodes_a = list(map(int, input().strip().split()))
        nodes_b = list(map(int, input().strip().split()))
        for x in nodes_a:
            a.append(x)
        for x in nodes_b:
            b.append(x)
        a.head = merge(a.head,b.head)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Function to merge two sorted lists in one
	using constant space.
	
	Function Arguments: head_a and head_b (head reference of both the sorted lists)
	Return Type: head of the obtained list after merger.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
	Contributed By: Nagendra Jha
'''
def merge(head_a,head_b):
    #code here
    global a
    elements = []
    curr_node = head_a
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    curr_node = head_b
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    elements = sorted(elements)
    a = LinkedList()
    for i in elements:
        a.append(i)
    return a.head

================================================
FILE: Microsoft/relativeSorting.py
================================================
def relativeSorting(A1,A2):
    common_elements = set(A1).intersection(set(A2))
    extra = set(A1).difference(set(A2))
    out = []
    for i in A2:
        s = [i] * A1.count(i)
        out.extend(s)
    extra_out = []
    for j in extra:
        u = [j] * A1.count(j)
        extra_out.extend(u)
    out = out + sorted(extra_out)
    return " ".join(str(i) for i in out)
    
if __name__ == '__main__':
    t = int(input())
    for tcase in range(t):
        N,M = list(map(int,input().strip().split()))
        A1 = list(map(int,input().strip().split()))
        A2 = list(map(int,input().strip().split()))
        print (relativeSorting(A1,A2))

================================================
FILE: Morgan-Stanley/addTwoNumbers_LinkedListRep.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
# prints the elements of linked list starting with head
def printList(head):
    if head is None:
        print(' ')
        return
    curr_node = head
    while curr_node:
        print(curr_node.data,end=" ")
        curr_node=curr_node.next
    print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n_a = int(input())
        a = LinkedList() # create a new linked list 'a'.
        nodes_a = list(map(int, input().strip().split()))
        nodes_a = nodes_a[::-1] # reverse the input array
        for x in nodes_a:
            a.append(x)  # add to the end of the list
        n_b =int(input())
        b = LinkedList()  # create a new linked list 'b'.
        nodes_b = list(map(int, input().strip().split()))
        nodes_b = nodes_b[::-1]  # reverse the input array
        for x in nodes_b:
            b.append(x)  # add to the end of the list
        result_head = addBoth(a.head,b.head)
        printList(result_head)
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Function to add two numbers represented 
	in the form of the linked list.
	
	Function Arguments: head_a and head_b (heads of both the linked lists)
	Return Type: head of the resultant linked list.
    
    __>IMP : numbers are represented in reverse in the linked list.
    Ex:
        145 is represented as  5->4->1.
    
    resultant head is expected in the same format.
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
'''
def addBoth(head_a,head_b):
    #code here
    result = LinkedList()
    num1 = ""
    curr_node = head_a
    while curr_node != None:
        num1 += str(curr_node.data)
        curr_node = curr_node.next
    num1 = num1[::-1]
    num2 = ""
    curr_node = head_b
    while curr_node != None:
        num2 += str(curr_node.data)
        curr_node = curr_node.next
    num2 = num2[::-1]
    num = int(num1) + int(num2)
    num = str(num)[::-1]
    for i in num:
        result.append(i)
    return result.head

================================================
FILE: Myntra/countOfInversionsArray.py
================================================
# GeeksForGeeks Code - Copied#
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for tt in range(t):
        n = int(input())
        a = list(map(int, input().strip().split()))
        print(Inversion_Count(a,n))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to return total number of inversions
	present in the array.
	
	Function Arguments: array a and size n
	Return Type: Integer 
'''
def Inversion_Count(arr,n):
    if a == sorted(a):
        return 0
    temp_arr = [0]*n
    return mergesort(arr,temp_arr,0,n-1)
    
def mergesort(arr,temp_arr,left,right):
    inv_count = 0
    if left < right:
        mid = (left + right)//2
        inv_count = mergesort(arr,temp_arr,left,mid)
        inv_count += mergesort(arr,temp_arr,mid+1,right)
        inv_count += merge(arr,temp_arr,left,mid,right)
    return inv_count
    
def merge(arr,temp_arr,left, mid, right): 
    # Merge the temp arrays back into arr[l..r] 
    i = left     # Initial index of first subarray 
    j = mid+1     # Initial index of second subarray 
    k = left     # Initial index of merged subarray 
    invcount = 0
    while i <= mid and j <= right: 
        if arr[i] <= arr[j]:
            temp_arr[k] = arr[i] 
            i += 1
        else: 
            temp_arr[k] = arr[j]
            invcount += (mid - i + 1)
            j += 1
        k += 1
    # Copy the remaining elements of L[], if there 
    # are any 
    while i <= mid: 
        temp_arr[k] = arr[i] 
        i += 1
        k += 1
    # Copy the remaining elements of R[], if there 
    # are any 
    while j <= right: 
        temp_arr[k] = arr[j] 
        j += 1
        k += 1
        
    for lr in range(left, right + 1): 
        arr[lr] = temp_arr[lr] 
    return invcount


================================================
FILE: Myntra/removeDuplicatesSortedLinkedList.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
    
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n = int(input())
        a = LinkedList() # create a new linked list 'a'.
        nodes = list(map(int, input().strip().split()))
        for x in nodes:
            a.append(x)
        removeDuplicates(a.head)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to remove duplicates from given 
	sorted linked list.
	
	Function Arguments: head (head of the given linked list) 
	Return Type: none, just remove the duplicates from the list.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
'''
def removeDuplicates(head):
    #code here
    global a
    curr_node = head
    duplicateTracker = []
    while curr_node != None:
        if curr_node.data not in duplicateTracker:
            duplicateTracker.append(curr_node.data)
        curr_node = curr_node.next
    a = LinkedList()
    for x in duplicateTracker:
        a.append(x)

================================================
FILE: Nagarro/isAnagram.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
    t = int(input())
    for i in range(t):
        a,b=map(str,input().strip().split())
        if(isAnagram(a,b)):
            print("YES")
        else:
            print("NO") 
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''Your task is to check given two strings
   are anagrams or not.
   a,b: given strings
   
   Return True or False accordingly.
   
   -> You don't need to print anything.Return type of function
   is boolean.
'''
def isAnagram(a,b):
    #code here
    import collections
    freqs_a = collections.Counter(a)
    freqs_b = collections.Counter(b)
    if (set(a) == set(b)) and (sorted(freqs_a.values()) == sorted(freqs_b.values())):
        return True
    else:
        return False

================================================
FILE: Nielsen/README.md
================================================
## Interview process for Senior SDE roles (Personal Experience)  
1. BarRaiser Round.  
2. Technical Interview rounds if BarRaiser is passed.
   - Technical Deep dive on projects listed in the CV - Questions on scalability of the architectures, pipelines, AWS cost saving opportunities etc.  
   - Coding questions on Arrays related to combinatorial optimization concepts.  


================================================
FILE: OYO_Rooms/FindzeroSumSubArrays.py
================================================
def subArrayExists(arr,n):
    ##Your code here
    hashMap = {}
    out = []
    sum1 = 0
    for i in range(n):
        sum1 += arr[i]
        if sum1==0:
            out.append((0,i))
        al = []
        if sum1 in hashMap:
            al = hashMap.get(sum1)
            for it in range(len(al)):
                out.append((al[it]+1,i))
        al.append(i)
        hashMap[sum1] = al
    return len(out)
    
    
if __name__ == '__main__':
    t = int(input())
    for tcase in range(t):
        n = int(input())
        arr = list(map(int,input().strip().split()))
        print (subArrayExists(arr,n))

================================================
FILE: OYO_Rooms/parenthesisChecker.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
#Contributed by : Nagendra Jha
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    test_cases = int(input())
    for cases in range(test_cases) :
        #n = int(input())
        #n,k = map(int,imput().strip().split())
        #a = list(map(int,input().strip().split()))
        s = str(input())
        if ispar(s):
            print("balanced")
        else:
            print("not balanced")
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
Function Arguments :
		@param  : s (given string containing parenthesis) 
		@return : boolean True or False
'''

def isMatchingPair(c1,c2):
    if (c1=='(') & (c2==')'):
        return True
    elif (c1=='{') & (c2=='}'):
        return True
    elif (c1=='[') & (c2==']'):
        return True
    else:
        return False
        
def ispar(s):
    # code here
    import queue
    stack = queue.LifoQueue()
    
    for i in range(len(s)):
        if ((s[i] == '{') | (s[i] == '[') | (s[i] == '(')):
            stack.put(s[i])
        if ((s[i] == '}') | (s[i] == ']') | (s[i] == ')')):
            if stack.empty():
                return False
            elif not isMatchingPair(stack.get(),s[i]):
                return False
        
    if stack.empty():
        return True
    else:
        return False

================================================
FILE: OYO_Rooms/removeDuplicatesSortedLinkedList.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
    
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n = int(input())
        a = LinkedList() # create a new linked list 'a'.
        nodes = list(map(int, input().strip().split()))
        for x in nodes:
            a.append(x)
        removeDuplicates(a.head)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Your task is to remove duplicates from given 
	sorted linked list.
	
	Function Arguments: head (head of the given linked list) 
	Return Type: none, just remove the duplicates from the list.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
'''
def removeDuplicates(head):
    #code here
    global a
    curr_node = head
    duplicateTracker = []
    while curr_node != None:
        if curr_node.data not in duplicateTracker:
            duplicateTracker.append(curr_node.data)
        curr_node = curr_node.next
    a = LinkedList()
    for x in duplicateTracker:
        a.append(x)

================================================
FILE: Oracle/merge2SortedLinkedLists.py
================================================
{
#Initial Template for Python 3
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init__(self):
        self.head = None
    # creates a new node with given value and appends it at the end of the linked list
    def append(self, new_value):
        new_node = Node(new_value)
        if self.head is None:
            self.head = new_node
            return
        curr_node = self.head
        while curr_node.next is not None:
            curr_node = curr_node.next
        curr_node.next = new_node
    # prints the elements of linked list starting with head
    def printList(self):
        if self.head is None:
            print(' ')
            return
        curr_node = self.head
        while curr_node:
            print(curr_node.data,end=" ")
            curr_node=curr_node.next
        print(' ')
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        n,m = map(int, input().strip().split())
        a = LinkedList() # create a new linked list 'a'.
        b = LinkedList() # create a new linked list 'b'.
        nodes_a = list(map(int, input().strip().split()))
        nodes_b = list(map(int, input().strip().split()))
        for x in nodes_a:
            a.append(x)
        for x in nodes_b:
            b.append(x)
        a.head = merge(a.head,b.head)
        a.printList()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
	Function to merge two sorted lists in one
	using constant space.
	
	Function Arguments: head_a and head_b (head reference of both the sorted lists)
	Return Type: head of the obtained list after merger.
	{
		# Node Class
		class Node:
		    def __init__(self, data):   # data -> value stored in node
		        self.data = data
		        self.next = None
	}
	Contributed By: Nagendra Jha
'''
def merge(head_a,head_b):
    #code here
    global a
    elements = []
    curr_node = head_a
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    curr_node = head_b
    while curr_node != None:
        elements.append(curr_node.data)
        curr_node = curr_node.next
    elements = sorted(elements)
    a = LinkedList()
    for i in elements:
        a.append(i)
    return a.head

================================================
FILE: Paytm/Convert_Infix_To_Postfix.py
================================================
{
#Initial Template for Python 3
import atexit
import io
import sys
# This code is contributed by Nikhil Kumar Singh(nickzuck_007)
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    test_cases = int(input())
    for cases in range(test_cases) :
        exp = str(input())
        print(InfixtoPostfix(exp))
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
'''
Function Arguments :
		@param  : exp (given infix expression)
		@return : string
'''
def InfixtoPostfix(exp):
    #code here
    import string
    stack = []
    prec = {'^':4,'*':3,'/':3,'+':2,'-':2,'(':1}
    postfixexp = []
    tokens = list(exp)
    for token in tokens:
        if ((token in string.ascii_lowercase) | (token in "0123456789") | (token in string.ascii_uppercase)):
            postfixexp.append(token)
        elif token == '(':
            stack.append(token)
        elif token == ')':
            if len(stack)!=0:
                topToken = stack.pop()
                while topToken != '(':
                    postfixexp.append(topToken)
                    topToken = stack.pop()
        else:
            if len(stack) != 0:
                while (len(stack)!=0) and (prec[stack[-1]] >= prec[token]):
                    postfixexp.append(stack.pop())
            stack.append(token)
    while len(stack)!=0:
        postfixexp.append(stack.pop())
    return "".join(postfixexp)

================================================
FILE: Paytm/binaryArraySort.py
================================================
{
#Initial Template for Python 3
import math
def main():
        T=int(input())
        while(T>0):
            N=int(input())
            A=list(map(int,input().split()))
            
            binSort(A,N)
            
            for i in A:
                print(i,end=" ")
            print()
            
            T-=1
if __name__ == "__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
##Complete this function
def binSort(arr, n): 
    #Your code here
    
    
    '''
    No need to print the array
    '''
    c0 = arr.count(0)
    c1 = arr.count(1)
    for i in range(c0):
        arr[i] = 0
    for i in range(c0,c0+c1):
        arr[i] = 1

================================================
FILE: Paytm/frequencyLimitedRangeArrayElements.py
================================================
{
#Initial Template for Python 3
import math
def main():
    
    T=int(input())
    
    while(T>0):
        
        
        N=int(input())
        
        A=[int(x) for x in input().strip().split()]
        printfrequency(A,N)
        
        print()
        
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function
def printfrequency(A,N):
    #Your Code here
    import collections
    freq_dict = collections.Counter(A)
    for i in range(1,N+1):
        print (freq_dict[i],end=" ")

================================================
FILE: Paytm/subarrayWithZeroSum.py
================================================
{
#Initial Template for Python 3
def main():
    T=int(input())
    while(T>0):
        
        n=int(input())
        arr=[int(x) for x in input().strip().split()]
        if(subArrayExists(arr,n)):
            print("Yes")
        else:
            print("No")
        
        
        T-=1
if __name__=="__main__":
    main()
}
''' This is a function problem.You only need to complete the function given below '''
#User function Template for python3
#Complete this function

def allSubArrays(L,L2=None):
    if L2==None:
        L2 = L[:-1]
    if L==[]:
        if L2==[]:
            return []
        return allSubArrays(L2,L2[:-1])
    return [L]+allSubArrays(L[1:],L2)
    
def subArrayExists(arr,n):
    ##Your code here
    #Return true or false
    if 0 in arr:
        return True
    else:
        allsubarrays = allSubArrays(arr)
        for s in allsubarrays:
            if sum(s) == 0:
                return True
    return False

================================================
FILE: Qalcomm/ImplementSTRSTR.py
================================================
{
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == '__main__':
    t=int(input())
    for cases in range(t):
        s,p =input().strip().split()
        print(strstr(s,p))

}
''' This is a function problem.You only need to complete the function given below '''
'''
	Your task is to return the index of the pattern
	present in the given string.
	
	Function Arguments: s (given text), p(given pattern)
	Return Type: Integer.
	
'''
def strstr(s,p):
    #code here
    import re
    loc = re.search(p,s)
    if loc is not None:
        return (loc.start())
    else:
        return -1

================================================
FILE: Qalcomm/addTwoNumbers_LinkedListRep.py
================================================
{
#Initial Template for Python 3
#Contributed by : Nagendra Jha
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
# Node Class
class Node:
    def __init__(self, data):   # data -> value stored in node
        self.data = data
        self.next = None
# Linked List Class
class LinkedList:
    def __init
Download .txt
gitextract_je5aerut/

├── .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
├── 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
├── DATFreightAnalytics/
│   └── 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
│   └── problem02/
│       └── countMe.py
├── 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
├── Nielsen/
│   └── README.md
├── 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
Download .txt
SYMBOL INDEX (320 symbols across 107 files)

FILE: 6sense/findWordInGrid.py
  class word_seek (line 23) | class word_seek:
    method __init__ (line 25) | def __init__(self):
    method search_grid (line 31) | def search_grid(self, grid, row, col, word):
    method patternSearch (line 49) | def patternSearch(self, grid, word):

FILE: Accolite/binaryArraySort.py
  function main (line 4) | def main():
  function binSort (line 23) | def binSort(arr, n):

FILE: Accolite/merge2SortedLinkedLists.py
  class Node (line 4) | class Node:
    method __init__ (line 5) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 9) | class LinkedList:
    method __init__ (line 10) | def __init__(self):
    method append (line 13) | def append(self, new_value):
    method printList (line 23) | def printList(self):
  function merge (line 64) | def merge(head_a,head_b):

FILE: Accolite/rotateLinkedListByKelements.py
  class Node (line 2) | class Node:
    method __init__ (line 3) | def __init__(self, data):
  class LinkedList (line 6) | class LinkedList:
    method __init__ (line 7) | def __init__(self):
    method push (line 9) | def push(self, new_data):
    method printList (line 13) | def printList(self):
  function rotateList (line 47) | def rotateList(head, k):

FILE: Adobe/QuickSort.py
  function quickSort (line 16) | def quickSort(arr,low,high):
  function partition (line 28) | def partition(arr,low,high):

FILE: Adobe/WinnerOfElection.py
  function main (line 4) | def main():
  function winner (line 21) | def winner(arr,n):

FILE: Adobe/checkIfStringsAreRotations.py
  function write (line 11) | def write():
  function areRotations (line 33) | def areRotations(s1,s2):

FILE: Adobe/countOfInversionsArray.py
  function write (line 12) | def write():
  function Inversion_Count (line 30) | def Inversion_Count(arr,n):
  function mergesort (line 36) | def mergesort(arr,temp_arr,left,right):
  function merge (line 45) | def merge(arr,temp_arr,left, mid, right):

FILE: Adobe/parenthesisChecker.py
  function write (line 12) | def write():
  function isMatchingPair (line 34) | def isMatchingPair(c1,c2):
  function ispar (line 44) | def ispar(s):

FILE: Amazon/Delete_Node_Without_HeadPointer.py
  class Node (line 1) | class Node(object):
    method __init__ (line 2) | def __init__(self,dataVal,nextNode=None):
    method getData (line 6) | def getData(self):
    method setData (line 9) | def setData(self,val):
    method getNextNode (line 12) | def getNextNode(self):
    method setNextNode (line 15) | def setNextNode(self,val):
  class LinkedList (line 18) | class LinkedList(object):
    method __init__ (line 19) | def __init__(self,head=None):
    method getSize (line 23) | def getSize(self):
    method addNode (line 26) | def addNode(self,data):
    method printNode (line 33) | def printNode(self):
    method deleteNode (line 39) | def deleteNode(self,value):

FILE: Amazon/EquilibriumPointFirstOccurWhere.py
  function main (line 4) | def main():
  function equilibriumPoint (line 18) | def equilibriumPoint(A, N):

FILE: Amazon/FindzeroSumSubArrays.py
  function subArrayExists (line 1) | def subArrayExists(arr,n):

FILE: Amazon/ImplementSTRSTR.py
  function write (line 11) | def write():
  function strstr (line 29) | def strstr(s,p):

FILE: Amazon/MaximumOfMinimumsOfAllWindowSizes.py
  function printMaxOfMin (line 45) | def printMaxOfMin(a,n):
  function write (line 92) | def write():

FILE: Amazon/Possible_Words_Phone_Digits.py
  function main (line 4) | def main():
  function possibleWords (line 24) | def possibleWords(a,N):

FILE: Amazon/countOfInversionsArray.py
  function write (line 12) | def write():
  function Inversion_Count (line 30) | def Inversion_Count(arr,n):
  function mergesort (line 36) | def mergesort(arr,temp_arr,left,right):
  function merge (line 45) | def merge(arr,temp_arr,left, mid, right):

FILE: Amazon/keypadTyping.py
  function keypadTyping (line 1) | def keypadTyping(s):

FILE: Amazon/merge2SortedLinkedLists.py
  class Node (line 4) | class Node:
    method __init__ (line 5) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 9) | class LinkedList:
    method __init__ (line 10) | def __init__(self):
    method append (line 13) | def append(self, new_value):
    method printList (line 23) | def printList(self):
  function merge (line 64) | def merge(head_a,head_b):

FILE: Amazon/missingSmallestPositiveNumber.py
  function main (line 4) | def main():
  function missingNumber (line 21) | def missingNumber(arr,n):

FILE: Amazon/moveAllZerosToEndOfArray.py
  function moveZerosToEnd (line 1) | def moveZerosToEnd(arr):

FILE: Amazon/parenthesisChecker.py
  function write (line 12) | def write():
  function isMatchingPair (line 34) | def isMatchingPair(c1,c2):
  function ispar (line 44) | def ispar(s):

FILE: Amazon/relativeSorting.py
  function relativeSorting (line 1) | def relativeSorting(A1,A2):

FILE: Amazon/rotateLinkedListByKelements.py
  class Node (line 2) | class Node:
    method __init__ (line 3) | def __init__(self, data):
  class LinkedList (line 6) | class LinkedList:
    method __init__ (line 7) | def __init__(self):
    method push (line 9) | def push(self, new_data):
    method printList (line 13) | def printList(self):
  function rotateList (line 47) | def rotateList(head, k):

FILE: Betterworks/print.py
  function doop (line 19) | def doop(mydict):

FILE: Bloomberg/moveAllZerosToEndOfArray.py
  function moveZerosToEnd (line 1) | def moveZerosToEnd(arr):

FILE: BrightMoney/LongestBalancedSubstring.py
  function findMaxLen (line 13) | def findMaxLen(string):

FILE: BrightMoney/printSpirally.py
  function generateMatrix (line 7) | def generateMatrix(n):

FILE: Facebook/ImplementSTRSTR.py
  function write (line 11) | def write():
  function strstr (line 29) | def strstr(s,p):

FILE: FactSet/convertArrayToWave.py
  function main (line 4) | def main():
  function convertToWave (line 29) | def convertToWave(A,N):

FILE: Flipkart/addTwoNumbers_LinkedListRep.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
  function printList (line 35) | def printList(head):
  function addBoth (line 83) | def addBoth(head_a,head_b):

FILE: Flipkart/countOfInversionsArray.py
  function write (line 12) | def write():
  function Inversion_Count (line 30) | def Inversion_Count(arr,n):
  function mergesort (line 36) | def mergesort(arr,temp_arr,left,right):
  function merge (line 45) | def merge(arr,temp_arr,left, mid, right):

FILE: Flipkart/parenthesisChecker.py
  function write (line 12) | def write():
  function isMatchingPair (line 34) | def isMatchingPair(c1,c2):
  function ispar (line 44) | def ispar(s):

FILE: Fractal_Analytics/countChampNumbers.py
  function countChampNumbers (line 8) | def countChampNumbers(X,Y):

FILE: Fractal_Analytics/countOfAnagrams.py
  function countAnagrams (line 7) | def countAnagrams(text,word):

FILE: Fractal_Analytics/numberOfGroups.py
  function numGroups (line 25) | def numGroups(poles):

FILE: Fre8wise/manipulate_string.py
  function changeString (line 15) | def changeString(s):

FILE: Goldman-Sachs/convertArrayToWave.py
  function main (line 4) | def main():
  function convertToWave (line 29) | def convertToWave(A,N):

FILE: Goldman-Sachs/numberOfSquares_in_NbyN_CheesBoard.py
  function num_of_squares (line 1) | def num_of_squares(n):

FILE: Goldman-Sachs/printNumbersContain123.py
  function contains123 (line 1) | def contains123(arr):

FILE: Goldman-Sachs/repeatingCharacter_LeftmostOccurrence.py
  function write (line 11) | def write():
  function repeatingCharacter (line 34) | def repeatingCharacter(s):

FILE: Google/First_Recurring_Character_In_String.py
  function firstRecurringChar (line 4) | def firstRecurringChar(input_string):

FILE: Google/allocateMinimumPages.py
  function isValid (line 2) | def isValid(arr,n,k,mi):
  function allocMinPages (line 15) | def allocMinPages(arr,n,k):

FILE: Google/checkPairsWithGivenSum.py
  function isPairWithGivenSum (line 11) | def isPairWithGivenSum(arr,n,x):

FILE: Google/maxIndexDiffOfArray.py
  function main (line 4) | def main():
  function maxIndexDiff (line 21) | def maxIndexDiff(arr, n):

FILE: Grofers/QuickSort.py
  function quickSort (line 16) | def quickSort(arr,low,high):
  function partition (line 28) | def partition(arr,low,high):

FILE: Guardant-Health/maintainMinimumStartingNumber.py
  function minStartNumber (line 28) | def minStartNumber(arr):

FILE: Hike/QuickSort.py
  function quickSort (line 16) | def quickSort(arr,low,high):
  function partition (line 28) | def partition(arr,low,high):

FILE: IQLECT/LargestPrimeFromSubsetSum.py
  function largestPrime (line 40) | def largestPrime(a):
  function testLargestPrime (line 81) | def testLargestPrime():

FILE: Infrrd/problem01/maximumRowsWithAll1s.py
  function maximumRows (line 3) | def maximumRows(binary_matrix,K):

FILE: Infrrd/problem02/countMe.py
  function countMe (line 1) | def countMe(arrA,arrL,arrR,arrX):
  function countOfNums (line 10) | def countOfNums(array,target):

FILE: Instabase/checkPairsWithGivenSum.py
  function isPairWithGivenSum (line 12) | def isPairWithGivenSum(arr,n,x):

FILE: Intuit/BuySellStock.py
  function main (line 4) | def main():
  function stockBuySell (line 21) | def stockBuySell(A,n):

FILE: Intuit/binaryArraySort.py
  function main (line 4) | def main():
  function binSort (line 23) | def binSort(arr, n):

FILE: Kritikal-Solutions/Delete_Without_Head_Pointer.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
    method getNode (line 34) | def getNode(self,value): # return node with given value, if not presen...
    method printList (line 43) | def printList(self):
  function deleteNode (line 82) | def deleteNode(curr_node):

FILE: LeadSquared/UniqueWaysToClimbStaircase.py
  function countWays (line 13) | def countWays(n,m):
  function countWays1 (line 42) | def countWays1(n,args):

FILE: LeadSquared/maximumSumLikeTimeCoefficients.py
  function maxSumLikeTimeCoeff (line 23) | def maxSumLikeTimeCoeff(arr,N):

FILE: LeadSquared/totalDistanceByStreetLights.py
  function total_distance (line 26) | def total_distance(intervals):

FILE: MAQ_Software/Closet0s1s2s.py
  function write (line 11) | def write():
  function segragate012 (line 25) | def segragate012(a,n):

FILE: MakeMyTrip/rotateLinkedListByKelements.py
  class Node (line 2) | class Node:
    method __init__ (line 3) | def __init__(self, data):
  class LinkedList (line 6) | class LinkedList:
    method __init__ (line 7) | def __init__(self):
    method push (line 9) | def push(self, new_data):
    method printList (line 13) | def printList(self):
  function rotateList (line 47) | def rotateList(head, k):

FILE: MakeMyTrip/sortedLinkedList012s.py
  function write (line 12) | def write():
  class Node (line 15) | class Node:
    method __init__ (line 16) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 20) | class LinkedList:
    method __init__ (line 21) | def __init__(self):
    method append (line 24) | def append(self, new_value):
  function printList (line 34) | def printList(head):
  function segregate (line 70) | def segregate(head):

FILE: Microsoft/countOfInversionsArray.py
  function write (line 12) | def write():
  function Inversion_Count (line 30) | def Inversion_Count(arr,n):
  function mergesort (line 36) | def mergesort(arr,temp_arr,left,right):
  function merge (line 45) | def merge(arr,temp_arr,left, mid, right):

FILE: Microsoft/merge2SortedLinkedLists.py
  class Node (line 4) | class Node:
    method __init__ (line 5) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 9) | class LinkedList:
    method __init__ (line 10) | def __init__(self):
    method append (line 13) | def append(self, new_value):
    method printList (line 23) | def printList(self):
  function merge (line 64) | def merge(head_a,head_b):

FILE: Microsoft/relativeSorting.py
  function relativeSorting (line 1) | def relativeSorting(A1,A2):

FILE: Morgan-Stanley/addTwoNumbers_LinkedListRep.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
  function printList (line 35) | def printList(head):
  function addBoth (line 83) | def addBoth(head_a,head_b):

FILE: Myntra/countOfInversionsArray.py
  function write (line 12) | def write():
  function Inversion_Count (line 30) | def Inversion_Count(arr,n):
  function mergesort (line 36) | def mergesort(arr,temp_arr,left,right):
  function merge (line 45) | def merge(arr,temp_arr,left, mid, right):

FILE: Myntra/removeDuplicatesSortedLinkedList.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
    method printList (line 35) | def printList(self):
  function removeDuplicates (line 72) | def removeDuplicates(head):

FILE: Nagarro/isAnagram.py
  function write (line 11) | def write():
  function isAnagram (line 33) | def isAnagram(a,b):

FILE: OYO_Rooms/FindzeroSumSubArrays.py
  function subArrayExists (line 1) | def subArrayExists(arr,n):

FILE: OYO_Rooms/parenthesisChecker.py
  function write (line 12) | def write():
  function isMatchingPair (line 34) | def isMatchingPair(c1,c2):
  function ispar (line 44) | def ispar(s):

FILE: OYO_Rooms/removeDuplicatesSortedLinkedList.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
    method printList (line 35) | def printList(self):
  function removeDuplicates (line 72) | def removeDuplicates(head):

FILE: Oracle/merge2SortedLinkedLists.py
  class Node (line 4) | class Node:
    method __init__ (line 5) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 9) | class LinkedList:
    method __init__ (line 10) | def __init__(self):
    method append (line 13) | def append(self, new_value):
    method printList (line 23) | def printList(self):
  function merge (line 64) | def merge(head_a,head_b):

FILE: Paytm/Convert_Infix_To_Postfix.py
  function write (line 12) | def write():
  function InfixtoPostfix (line 27) | def InfixtoPostfix(exp):

FILE: Paytm/binaryArraySort.py
  function main (line 4) | def main():
  function binSort (line 23) | def binSort(arr, n):

FILE: Paytm/frequencyLimitedRangeArrayElements.py
  function main (line 4) | def main():
  function printfrequency (line 25) | def printfrequency(A,N):

FILE: Paytm/subarrayWithZeroSum.py
  function main (line 3) | def main():
  function allSubArrays (line 23) | def allSubArrays(L,L2=None):
  function subArrayExists (line 32) | def subArrayExists(arr,n):

FILE: Qalcomm/ImplementSTRSTR.py
  function write (line 11) | def write():
  function strstr (line 29) | def strstr(s,p):

FILE: Qalcomm/addTwoNumbers_LinkedListRep.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
  function printList (line 35) | def printList(head):
  function addBoth (line 83) | def addBoth(head_a,head_b):

FILE: Quikr/BuySellStock.py
  function main (line 4) | def main():
  function stockBuySell (line 21) | def stockBuySell(A,n):

FILE: RelianceJIO/CamelCaseToSnakeCase.py
  function convert_string (line 22) | def convert_string(s:str) -> str:

FILE: RelianceJIO/getSmallestNumber.py
  function div_count (line 10) | def div_count(n):
  function smallestNumber (line 45) | def smallestNumber(n,ndn):

FILE: Salesforce/BuySellStock.py
  function main (line 4) | def main():
  function stockBuySell (line 21) | def stockBuySell(A,n):

FILE: Samsung/merge2SortedLinkedLists.py
  class Node (line 4) | class Node:
    method __init__ (line 5) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 9) | class LinkedList:
    method __init__ (line 10) | def __init__(self):
    method append (line 13) | def append(self, new_value):
    method printList (line 23) | def printList(self):
  function merge (line 64) | def merge(head_a,head_b):

FILE: Samsung/missingSmallestPositiveNumber.py
  function main (line 4) | def main():
  function missingNumber (line 21) | def missingNumber(arr,n):

FILE: Samsung/moveAllZerosToEndOfArray.py
  function moveZerosToEnd (line 1) | def moveZerosToEnd(arr):

FILE: SkyPointCloud/binarySearch.py
  function binarySearch (line 5) | def binarySearch(arr,x):

FILE: SkyPointCloud/modifyString.py
  function isPrime (line 15) | def isPrime(n) :
  function sort_string (line 36) | def sort_string(s,n):

FILE: Snapdeal/addTwoNumbers_LinkedListRep.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
  function printList (line 35) | def printList(head):
  function addBoth (line 83) | def addBoth(head_a,head_b):

FILE: SymphonyAI/maximumHeightOfMudSegment.py
  function maxHeight (line 74) | def maxHeight(wallPositions,wallHeights):

FILE: Thoughtworks/ScheduleInterviews.py
  function divideWorkingHours (line 4) | def divideWorkingHours(start_time:datetime.datetime,
  function removeOverlaps (line 17) | def removeOverlaps(slots:List[Tuple],break_hour:Tuple) -> List[Tuple]:
  function scheduleInterviews (line 28) | def scheduleInterviews(attendees:dict,

FILE: Twilio/DiskSpaceAnalysis.py
  function segment (line 12) | def segment(x:int, space:List[int]) -> int:

FILE: Uber/getNewArray.py
  function productOfArray (line 11) | def productOfArray(arr):
  function newArray (line 17) | def newArray(arr):

FILE: Ushur/findPairs.py
  function find_pairs (line 9) | def find_pairs(n,socks):

FILE: VMWare/Convert_Infix_To_Postfix.py
  function write (line 12) | def write():
  function InfixtoPostfix (line 27) | def InfixtoPostfix(exp):

FILE: VMWare/maxIndexDiffOfArray.py
  function main (line 4) | def main():
  function maxIndexDiff (line 21) | def maxIndexDiff(arr, n):

FILE: VMWare/mergeKSortedLinkedLists.py
  function write (line 12) | def write():
  class Node (line 15) | class Node:
    method __init__ (line 16) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 20) | class LinkedList:
    method __init__ (line 21) | def __init__(self):
    method append (line 24) | def append(self, new_value):
  function printList (line 34) | def printList(head):
  function merge (line 83) | def merge(heads,n):

FILE: Visa/addNode_DoublyLinkedList.py
  class Node (line 2) | class Node:
    method __init__ (line 3) | def __init__(self, data):
  class DoublyLinkedList (line 7) | class DoublyLinkedList:
    method __init__ (line 8) | def __init__(self):
    method append (line 10) | def append(self, new_data):
    method printList (line 23) | def printList(self, node):
  function addNode (line 58) | def addNode(head, p, data):

FILE: Visa/populateList.py
  function solution (line 12) | def solution(numbers):

FILE: Visa/removeDuplicatesSortedLinkedList.py
  function write (line 12) | def write():
  class Node (line 16) | class Node:
    method __init__ (line 17) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 21) | class LinkedList:
    method __init__ (line 22) | def __init__(self):
    method append (line 25) | def append(self, new_value):
    method printList (line 35) | def printList(self):
  function removeDuplicates (line 72) | def removeDuplicates(head):

FILE: Walmart/GroupAnagrams.py
  function group_anagrams (line 14) | def group_anagrams(words:List[str]) -> List[Tuple[str]]:
  function group_anagrams_1 (line 44) | def group_anagrams_1(words:List[str]) -> List[Tuple[str]]:

FILE: Walmart/minimumCoins.py
  function minCoins (line 16) | def minCoins(coins:List[int],value:int) -> int:

FILE: Walmart/minimumCoinsRecursive.py
  function minimumCoinsRecursive (line 15) | def minimumCoinsRecursive(coins:List[int],value:int) -> int:

FILE: Yahoo/ThreeWayPartition.py
  function threeWayPartition (line 47) | def threeWayPartition(arr, n, a, b):

FILE: ZSAssociates/CrossSequence.py
  function solve (line 21) | def solve(N,A,K):

FILE: ZSAssociates/OutputOfProgram.py
  function plus_one (line 11) | def plus_one(batch_iter):
  function multiply_two_cols (line 16) | def multiply_two_cols(batch_iter):

FILE: ZSAssociates/OutputOfProgram2.py
  function MainProgram (line 1) | def MainProgram(iterable, x):
  function MainProg (line 20) | def MainProg(f):
  function Call (line 29) | def Call(num):

FILE: Zoho/merge2SortedLinkedLists.py
  class Node (line 4) | class Node:
    method __init__ (line 5) | def __init__(self, data):   # data -> value stored in node
  class LinkedList (line 9) | class LinkedList:
    method __init__ (line 10) | def __init__(self):
    method append (line 13) | def append(self, new_value):
    method printList (line 23) | def printList(self):
  function merge (line 64) | def merge(head_a,head_b):

FILE: Zoho/rearrangeArrayAlternately.py
  function main (line 4) | def main():
  function rearrange (line 26) | def rearrange(arr, n):
Condensed preview — 156 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (271K chars).
[
  {
    "path": ".gitignore",
    "chars": 1203,
    "preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packagi"
  },
  {
    "path": "6sense/README.md",
    "chars": 43,
    "preview": "# Hackerrank Test (Personal Experience):  \n"
  },
  {
    "path": "6sense/findWordInGrid.py",
    "chars": 2517,
    "preview": "\"\"\"\nRefer below link for the question:\n    https://www.geeksforgeeks.org/search-a-word-in-a-2d-grid-of-characters/\n\nSolu"
  },
  {
    "path": "Accenture/README.md",
    "chars": 1167,
    "preview": "# Interview Process - Data Engineer - Round 1 (Skills Interview):  \n+ Can a python class have 2 __init__ methods?  \n+ Qu"
  },
  {
    "path": "Accolite/binaryArraySort.py",
    "chars": 751,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            N=int(in"
  },
  {
    "path": "Accolite/merge2SortedLinkedLists.py",
    "chars": 2419,
    "preview": "{\n#Initial Template for Python 3\n# Node Class\nclass Node:\n    def __init__(self, data):   # data -> value stored in node"
  },
  {
    "path": "Accolite/rotateLinkedListByKelements.py",
    "chars": 1694,
    "preview": "{\nclass Node:\n    def __init__(self, data):\n        self.data = data\n        self.next = None\nclass LinkedList:\n    def "
  },
  {
    "path": "Adobe/QuickSort.py",
    "chars": 1054,
    "preview": "{\n#Initial Template for Python 3\nif __name__ == \"__main__\":\n    t=int(input())\n    for i in range(t):\n        n=int(inpu"
  },
  {
    "path": "Adobe/WinnerOfElection.py",
    "chars": 913,
    "preview": "{\n#Initial Template for Python 3\n    \ndef main():\n    T=int(input())\n    while(T>0):\n        \n        n=int(input())\n   "
  },
  {
    "path": "Adobe/checkIfStringsAreRotations.py",
    "chars": 1032,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "Adobe/countOfInversionsArray.py",
    "chars": 2117,
    "preview": "# GeeksForGeeks Code - Copied#\n{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Adobe/parenthesisChecker.py",
    "chars": 1609,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n#Contributed by : Nagendra Jha\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Amazon/DataEngineering/README.md",
    "chars": 435,
    "preview": "# Data Engineering Assessment (As of Oct 2024):\n+ Assessment redirected to Hackerank from Amazon Jobs profile configurat"
  },
  {
    "path": "Amazon/Delete_Node_Without_HeadPointer.py",
    "chars": 1739,
    "preview": "class Node(object):\n    def __init__(self,dataVal,nextNode=None):\n        self.data = dataVal\n        self.next = nextNo"
  },
  {
    "path": "Amazon/EquilibriumPointFirstOccurWhere.py",
    "chars": 828,
    "preview": "{\n# Initial Template for Python 3\nimport math\ndef main():\n    T = int(input())\n    while(T > 0):\n        N = int(input()"
  },
  {
    "path": "Amazon/FindzeroSumSubArrays.py",
    "chars": 613,
    "preview": "def subArrayExists(arr,n):\n    ##Your code here\n    hashMap = {}\n    out = []\n    sum1 = 0\n    for i in range(n):\n      "
  },
  {
    "path": "Amazon/ImplementSTRSTR.py",
    "chars": 835,
    "preview": "{\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "Amazon/JosephusProblem.py",
    "chars": 551,
    "preview": "{\nimport math\n//Position this line where user code will be pasted.\n    \ndef main():\n    \n    T=int(input())\n    \n    whi"
  },
  {
    "path": "Amazon/MaximumOfMinimumsOfAllWindowSizes.py",
    "chars": 3281,
    "preview": "#User function Template for python3\n\"\"\"\nGiven an integer array A[] of size N. The task is to find the maximum of the min"
  },
  {
    "path": "Amazon/Possible_Words_Phone_Digits.py",
    "chars": 916,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n    \n    T=int(input())\n    \n    while(T>0):\n        \n        N"
  },
  {
    "path": "Amazon/countOfInversionsArray.py",
    "chars": 2117,
    "preview": "# GeeksForGeeks Code - Copied#\n{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Amazon/getAggregationsByParsing.py",
    "chars": 1669,
    "preview": "#!/usr/bin/env python3.9\n# Asked in Thrasio Interview Process\n# Input:\n    \nsales_data = [{'channel':'Amazon', 'id':'AMZ"
  },
  {
    "path": "Amazon/keypadTyping.py",
    "chars": 486,
    "preview": "def keypadTyping(s):\n    for c in s:\n        print (mydict[c],end=\"\")\n    \nif __name__ == '__main__':\n    t = int(input("
  },
  {
    "path": "Amazon/merge2SortedLinkedLists.py",
    "chars": 2419,
    "preview": "{\n#Initial Template for Python 3\n# Node Class\nclass Node:\n    def __init__(self, data):   # data -> value stored in node"
  },
  {
    "path": "Amazon/missingSmallestPositiveNumber.py",
    "chars": 902,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "Amazon/moveAllZerosToEndOfArray.py",
    "chars": 352,
    "preview": "def moveZerosToEnd(arr):\n    arr_0 = [x for x in arr if x!=0]\n    zeros = [0] * (len(arr)-len(arr_0))\n    ans = arr_0 + "
  },
  {
    "path": "Amazon/parenthesisChecker.py",
    "chars": 1609,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n#Contributed by : Nagendra Jha\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Amazon/relativeSorting.py",
    "chars": 649,
    "preview": "def relativeSorting(A1,A2):\n    common_elements = set(A1).intersection(set(A2))\n    extra = set(A1).difference(set(A2))\n"
  },
  {
    "path": "Amazon/rotateLinkedListByKelements.py",
    "chars": 1694,
    "preview": "{\nclass Node:\n    def __init__(self, data):\n        self.data = data\n        self.next = None\nclass LinkedList:\n    def "
  },
  {
    "path": "AmericanExpress/README.md",
    "chars": 859,
    "preview": "# Interview Process for Engineer - II (2021) (Personal):  \n### First Round - Coding Round: Online Coding Round with time"
  },
  {
    "path": "Athena-Health/README.md",
    "chars": 1528,
    "preview": "# Interview Process for SMTS (Senior Member of Technical Staff) - 2021:  \n### First Round - Coding (Data Structures and "
  },
  {
    "path": "Betterworks/README.md",
    "chars": 1696,
    "preview": "# Hiring process for Betterworks Software Engineer Role (Personal Experience):  \n  \n## First round:  \n+ Discussion from "
  },
  {
    "path": "Betterworks/print.py",
    "chars": 730,
    "preview": "\"\"\"\nGiven a dictionary of elements:\n    mydict = {'one':1,\n              'two':2,\n              'three':3,\n             "
  },
  {
    "path": "Bloomberg/moveAllZerosToEndOfArray.py",
    "chars": 352,
    "preview": "def moveZerosToEnd(arr):\n    arr_0 = [x for x in arr if x!=0]\n    zeros = [0] * (len(arr)-len(arr_0))\n    ans = arr_0 + "
  },
  {
    "path": "BrightMoney/Knapsack.py",
    "chars": 29,
    "preview": "\"\"\"\n0-1 Knapsack problem\n\n\"\"\""
  },
  {
    "path": "BrightMoney/LongestBalancedSubstring.py",
    "chars": 1714,
    "preview": "\"\"\"\nLongest balanced substring given a string containing only parenthesis (open and\nclosed curly braces)\n\nRefer https://"
  },
  {
    "path": "BrightMoney/README.md",
    "chars": 1448,
    "preview": "# Coding questions on DoSelect Platform (Personal Experience) (Data Science roles - ML Engineering) (4 Coding questions "
  },
  {
    "path": "BrightMoney/countDistinctValidPANNumbers.py",
    "chars": 87,
    "preview": "\"\"\"\nGiven a paragraph of P words, find all valid PAN card numbers in that paragraph\n\"\"\""
  },
  {
    "path": "BrightMoney/printSpirally.py",
    "chars": 1058,
    "preview": "\"\"\"\nGiven an integer n, generate a square matrix from entries from 1 to n**2 in \nspiral pattern\n\n\"\"\"\n\ndef generateMatrix"
  },
  {
    "path": "Busigence/README.md",
    "chars": 223,
    "preview": "# Interview Process - Personal (Data Engineer - Python/Pyspark/Scala-spark) - 2021:  \n### First round:  \n+ Take Home ass"
  },
  {
    "path": "Busigence/Vikas_Chitturi.ipynb",
    "chars": 57739,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"DATA ENGINEER - PYTHON PYSPARK\"\n   "
  },
  {
    "path": "Byndr/README.md",
    "chars": 967,
    "preview": "# Interview Experience for Data Engineer (Big Data) - 2021:  \n### First Round:  \n+ What is Hive?  \n+ What is Hive metast"
  },
  {
    "path": "CloudCover/README.md",
    "chars": 891,
    "preview": "# Personal Experience for Data Engineer - 2021:  \n## First round:  \nLive Programming round - Given 1.5 hrs of time, you "
  },
  {
    "path": "DATFreightAnalytics/README.md",
    "chars": 415,
    "preview": "## Interview Process for Machine Learning Engineer (Personal Experience)  \n1. Resume Screening.\n2. Technical Assessment "
  },
  {
    "path": "Facebook/ImplementSTRSTR.py",
    "chars": 835,
    "preview": "{\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "FactSet/convertArrayToWave.py",
    "chars": 944,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n    \n    T=int(input())\n    \n    while(T>0):\n        \n        \n"
  },
  {
    "path": "Flipkart/addTwoNumbers_LinkedListRep.py",
    "chars": 3062,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Flipkart/countOfInversionsArray.py",
    "chars": 2117,
    "preview": "# GeeksForGeeks Code - Copied#\n{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Flipkart/parenthesisChecker.py",
    "chars": 1609,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n#Contributed by : Nagendra Jha\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Fractal_Analytics/Arrays.md",
    "chars": 545,
    "preview": "Given an array A of size N as an input, return the following:  \n  + for every element of array, find the sum of elements"
  },
  {
    "path": "Fractal_Analytics/Comparator.md",
    "chars": 655,
    "preview": "1. Write a comparator class with overloaded methods that perform below operations  \n   - a. `compare(int a,int b)` that "
  },
  {
    "path": "Fractal_Analytics/README.md",
    "chars": 1401,
    "preview": "# Interview Process for Analytics Consultant - 2019:  \n### First round:  \n+ Hackerrank Test (Python + SQL) or (R + SQL) "
  },
  {
    "path": "Fractal_Analytics/countChampNumbers.py",
    "chars": 761,
    "preview": "\"\"\"\nfind the count of champ numbers in given range [X,Y] (inclusive)\nChamp numbers are numbers which have all the digits"
  },
  {
    "path": "Fractal_Analytics/countOfAnagrams.py",
    "chars": 408,
    "preview": "\"\"\"\nGiven a text and a word, find the count of occurrences of anagrams\nof word in given text\n\n\"\"\"\n\ndef countAnagrams(tex"
  },
  {
    "path": "Fractal_Analytics/numberOfGroups.py",
    "chars": 1172,
    "preview": "\"\"\"\nA pole of the magnet is represented as \"01\" or \"10\"\n1 = North pole and 0 = South pole\nwe know the like poles of magn"
  },
  {
    "path": "Fractal_Analytics/sorting_words.md",
    "chars": 484,
    "preview": "Given a sentence, sort the words of a sentence according to the their individual lengths. If one or more words have same"
  },
  {
    "path": "Fractal_Analytics/substrings.md",
    "chars": 671,
    "preview": "\n2. Get the number of distinct substrings possible for a given string, you can use the below operations:  \n  \n   - a. Re"
  },
  {
    "path": "Fre8wise/README.md",
    "chars": 829,
    "preview": "# Process for Software engineer role:  \n## First round:  \n1. First round is with founder of the company - This is an exp"
  },
  {
    "path": "Fre8wise/manipulate_string.py",
    "chars": 552,
    "preview": "\"\"\"\nSolve the following algorithm problem:\n    Given a string, develop a solution that removes only 1's\n    in the begin"
  },
  {
    "path": "Goldman-Sachs/convertArrayToWave.py",
    "chars": 944,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n    \n    T=int(input())\n    \n    while(T>0):\n        \n        \n"
  },
  {
    "path": "Goldman-Sachs/numberOfSquares_in_NbyN_CheesBoard.py",
    "chars": 332,
    "preview": "def num_of_squares(n):\n    if n == 1:\n        return (1)\n    else:\n        nSquares = 0\n        for I in range(1,n+1):\n "
  },
  {
    "path": "Goldman-Sachs/printNumbersContain123.py",
    "chars": 533,
    "preview": "def contains123(arr):\n    c = {'1','2','3'}\n    tracker = []\n    arr = sorted(arr)\n    for i in arr:\n        a = set(str"
  },
  {
    "path": "Goldman-Sachs/repeatingCharacter_LeftmostOccurrence.py",
    "chars": 1198,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "Google/First_Recurring_Character_In_String.py",
    "chars": 413,
    "preview": "from collections import Counter\ninput_string = input()\n\ndef firstRecurringChar(input_string):\n    recurring_chars= []\n  "
  },
  {
    "path": "Google/allocateMinimumPages.py",
    "chars": 883,
    "preview": "import math\ndef isValid(arr,n,k,mi):\n    std = 1\n    curr = 0\n    for i in range(n):\n        if curr + arr[i] > mi:\n    "
  },
  {
    "path": "Google/checkPairsWithGivenSum.py",
    "chars": 767,
    "preview": "\"\"\"\nThis problem was recently asked by Google.\n\nGiven a list of numbers and a number k, return whether any two numbers f"
  },
  {
    "path": "Google/maxIndexDiffOfArray.py",
    "chars": 722,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "Grofers/QuickSort.py",
    "chars": 1054,
    "preview": "{\n#Initial Template for Python 3\nif __name__ == \"__main__\":\n    t=int(input())\n    for i in range(t):\n        n=int(inpu"
  },
  {
    "path": "Guardant-Health/README.md",
    "chars": 42,
    "preview": "# Hackerrank Test (Personal Experience)  \n"
  },
  {
    "path": "Guardant-Health/fallen_leaves.py",
    "chars": 939,
    "preview": "\"\"\"\nCoding Test - Hackerrank\n\nGiven an array that has number of leaves on N trees (size of array = N)(arr[i]\nrepresents "
  },
  {
    "path": "Guardant-Health/maintainMinimumStartingNumber.py",
    "chars": 845,
    "preview": "\"\"\"\nCoding Test - Hackerrank\n\nwhat is the minimum starting number to maintain such that the running sum will\nalways be a"
  },
  {
    "path": "HighRadius-Technologies/README.md",
    "chars": 1563,
    "preview": "## Interview questions (Personal Experience):  \n\n#### 1. Confusion matrix for any classification algorithm is showed and"
  },
  {
    "path": "Hike/QuickSort.py",
    "chars": 1054,
    "preview": "{\n#Initial Template for Python 3\nif __name__ == \"__main__\":\n    t=int(input())\n    for i in range(t):\n        n=int(inpu"
  },
  {
    "path": "IQLECT/LargestPrimeFromSubsetSum.py",
    "chars": 3562,
    "preview": "# Q)Find largest possible prime number that can be generated by adding all the elements of any subset of the given array"
  },
  {
    "path": "IQLECT/README.md",
    "chars": 69,
    "preview": "# Asked to solve these questions in-person (In office) (No platform)\n"
  },
  {
    "path": "InMobi/README.md",
    "chars": 781,
    "preview": "# Interview Process for Big Data Engineer 2020 (Personal):  \n1. First round of interview with onshore engineering manage"
  },
  {
    "path": "Infrrd/problem01/maximumRowsWithAll1s.py",
    "chars": 1415,
    "preview": "import collections\n\ndef maximumRows(binary_matrix,K):\n    N = len(binary_matrix)\n    M = len(binary_matrix[0])\n    numOf"
  },
  {
    "path": "Infrrd/problem02/countMe.py",
    "chars": 710,
    "preview": "def countMe(arrA,arrL,arrR,arrX):\n    resultCount = []\n    for b in range(len(arrX)):\n        targetX = arrX[b]\n        "
  },
  {
    "path": "Instabase/Add2BinaryStrings.py",
    "chars": 226,
    "preview": "\"\"\"\nAdd two binary strings and get the resultant\nHint:\n    Try it without converting individual entities into numerical "
  },
  {
    "path": "Instabase/README.md",
    "chars": 52,
    "preview": "# Coding questions on Enthire (Personal Experience)\n"
  },
  {
    "path": "Instabase/checkPairsWithGivenSum.py",
    "chars": 791,
    "preview": "\"\"\"\nDaily Coding Problem #1\nThis problem was recently asked by Google.\n\nGiven a list of numbers and a number k, return w"
  },
  {
    "path": "Intuit/BuySellStock.py",
    "chars": 1456,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "Intuit/binaryArraySort.py",
    "chars": 751,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            N=int(in"
  },
  {
    "path": "Kritikal-Solutions/Delete_Without_Head_Pointer.py",
    "chars": 2809,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "LeadSquared/README.md",
    "chars": 59,
    "preview": "# Coding Questions on mettl platform (Personal Experience)\n"
  },
  {
    "path": "LeadSquared/UniqueWaysToClimbStaircase.py",
    "chars": 1955,
    "preview": "\"\"\"\nThis question is asked in Interview\n    \nThere are n stairs, a person standing at the bottom wants to reach the \ntop"
  },
  {
    "path": "LeadSquared/maximumSumLikeTimeCoefficients.py",
    "chars": 956,
    "preview": "\"\"\"\nCoding Test - Round 1\n\nGiven an array of N integers (negative integers allowed) which say likings of\nN foods by a cu"
  },
  {
    "path": "LeadSquared/totalDistanceByStreetLights.py",
    "chars": 1331,
    "preview": "\"\"\"\nCoding Test - Round 1\n\nGiven N street lights, and an array of tuples which signify the start and \nend distances of s"
  },
  {
    "path": "MAQ_Software/Closet0s1s2s.py",
    "chars": 990,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "MakeMyTrip/rotateLinkedListByKelements.py",
    "chars": 1694,
    "preview": "{\nclass Node:\n    def __init__(self, data):\n        self.data = data\n        self.next = None\nclass LinkedList:\n    def "
  },
  {
    "path": "MakeMyTrip/sortedLinkedList012s.py",
    "chars": 2277,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Mastek/README.md",
    "chars": 1224,
    "preview": "Consider the below employee table where ManagerID is mapped to each EmployeeID:\n\nInput:\n| EmployeeID | EmployeeName | Ma"
  },
  {
    "path": "Mastek/computedepth.sql",
    "chars": 356,
    "preview": "-- Oracle solution\n\nWITH RecursiveCTE (lvl, ManagerID, EmployeeID) AS (\n   SELECT 1 AS lvl, ManagerID, EmployeeID\n   FRO"
  },
  {
    "path": "Microsoft/countOfInversionsArray.py",
    "chars": 2117,
    "preview": "# GeeksForGeeks Code - Copied#\n{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Microsoft/merge2SortedLinkedLists.py",
    "chars": 2419,
    "preview": "{\n#Initial Template for Python 3\n# Node Class\nclass Node:\n    def __init__(self, data):   # data -> value stored in node"
  },
  {
    "path": "Microsoft/relativeSorting.py",
    "chars": 649,
    "preview": "def relativeSorting(A1,A2):\n    common_elements = set(A1).intersection(set(A2))\n    extra = set(A1).difference(set(A2))\n"
  },
  {
    "path": "Morgan-Stanley/addTwoNumbers_LinkedListRep.py",
    "chars": 3062,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Myntra/countOfInversionsArray.py",
    "chars": 2117,
    "preview": "# GeeksForGeeks Code - Copied#\n{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Myntra/removeDuplicatesSortedLinkedList.py",
    "chars": 2380,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Nagarro/isAnagram.py",
    "chars": 1104,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "Nielsen/README.md",
    "chars": 375,
    "preview": "## Interview process for Senior SDE roles (Personal Experience)  \n1. BarRaiser Round.  \n2. Technical Interview rounds if"
  },
  {
    "path": "OYO_Rooms/FindzeroSumSubArrays.py",
    "chars": 613,
    "preview": "def subArrayExists(arr,n):\n    ##Your code here\n    hashMap = {}\n    out = []\n    sum1 = 0\n    for i in range(n):\n      "
  },
  {
    "path": "OYO_Rooms/parenthesisChecker.py",
    "chars": 1609,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n#Contributed by : Nagendra Jha\n_INPUT_LINES = sys.st"
  },
  {
    "path": "OYO_Rooms/removeDuplicatesSortedLinkedList.py",
    "chars": 2380,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Oracle/merge2SortedLinkedLists.py",
    "chars": 2419,
    "preview": "{\n#Initial Template for Python 3\n# Node Class\nclass Node:\n    def __init__(self, data):   # data -> value stored in node"
  },
  {
    "path": "Paytm/Convert_Infix_To_Postfix.py",
    "chars": 1643,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n# This code is contributed by Nikhil Kumar Singh(nic"
  },
  {
    "path": "Paytm/binaryArraySort.py",
    "chars": 751,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            N=int(in"
  },
  {
    "path": "Paytm/frequencyLimitedRangeArrayElements.py",
    "chars": 633,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n    \n    T=int(input())\n    \n    while(T>0):\n        \n        \n"
  },
  {
    "path": "Paytm/subarrayWithZeroSum.py",
    "chars": 949,
    "preview": "{\n#Initial Template for Python 3\ndef main():\n    T=int(input())\n    while(T>0):\n        \n        n=int(input())\n        "
  },
  {
    "path": "Qalcomm/ImplementSTRSTR.py",
    "chars": 835,
    "preview": "{\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput ="
  },
  {
    "path": "Qalcomm/addTwoNumbers_LinkedListRep.py",
    "chars": 3062,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Quikr/BuySellStock.py",
    "chars": 1456,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "README.md",
    "chars": 1798,
    "preview": "# Programming questions/Case studies/Theoretical questions/Design questions etc From Interviews and Coding Tests:  \n  \n+"
  },
  {
    "path": "RelianceJIO/CamelCaseToSnakeCase.py",
    "chars": 1011,
    "preview": "#!/usr/bin/python3.8\n\"\"\"\n\nWrite a function that converts camel_case string into snake case:\n    \n    Example:\n        \n "
  },
  {
    "path": "RelianceJIO/README.md",
    "chars": 113,
    "preview": "# First round:  \n## Hackerrarth Test with some data science questions (Objective) along with 2 coding question  \n"
  },
  {
    "path": "RelianceJIO/getSmallestNumber.py",
    "chars": 1408,
    "preview": "#!/usr/bin/python3.8\n\n\"\"\"\nP(N) gives all the numbers that divide given number N\n\nfind the smallest number number Y such "
  },
  {
    "path": "Salesforce/BuySellStock.py",
    "chars": 1456,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "Samsung/merge2SortedLinkedLists.py",
    "chars": 2419,
    "preview": "{\n#Initial Template for Python 3\n# Node Class\nclass Node:\n    def __init__(self, data):   # data -> value stored in node"
  },
  {
    "path": "Samsung/missingSmallestPositiveNumber.py",
    "chars": 902,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "Samsung/moveAllZerosToEndOfArray.py",
    "chars": 352,
    "preview": "def moveZerosToEnd(arr):\n    arr_0 = [x for x in arr if x!=0]\n    zeros = [0] * (len(arr)-len(arr_0))\n    ans = arr_0 + "
  },
  {
    "path": "SkyPointCloud/README.md",
    "chars": 1932,
    "preview": "# Interview process for skypoint cloud (Data engineer) (Personal Experience):  \n1. **Hackerearth Test**: objective quest"
  },
  {
    "path": "SkyPointCloud/binarySearch.py",
    "chars": 783,
    "preview": "\"\"\"\nCan you write the binary search algorithm for reverse sorted array?\n\n\"\"\"\ndef binarySearch(arr,x):\n    arr = sorted(a"
  },
  {
    "path": "SkyPointCloud/modifyString.py",
    "chars": 1496,
    "preview": "\"\"\"\nGiven a string, sort/modify the characters of string according to below rules:\n    \n    1. characters having prime a"
  },
  {
    "path": "Snapdeal/addTwoNumbers_LinkedListRep.py",
    "chars": 3062,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Swiggy/README.md",
    "chars": 1855,
    "preview": "# Personal Experience - Software Development Engineer - II (Data and ML Platform):  \n  \n## First Round (Computer Science"
  },
  {
    "path": "SymphonyAI/README.md",
    "chars": 1064,
    "preview": "Hackerrank Test (Personal Experience) (2020) \n===========================================\n______________________________"
  },
  {
    "path": "SymphonyAI/maximumHeightOfMudSegment.py",
    "chars": 3113,
    "preview": "\"\"\"\nProblem Statement\nA child likes to build mud walls by placing mud between sticks positioned on \na number line. The g"
  },
  {
    "path": "Tavant-Technologies/README.md",
    "chars": 1084,
    "preview": "## Interview with Senior Technical Architect (Glider discussion):  \n1. One Simple Coding question:\n   - Given a list of "
  },
  {
    "path": "Thomson-Reuters/README.md",
    "chars": 796,
    "preview": "# Interview Process - Personal (Machine Learning Engineer) - 2021:  \n### First Round - Hackerrank test:  \n+ Given a stri"
  },
  {
    "path": "Thoughtworks/README.md",
    "chars": 410,
    "preview": "Source of Problem Statement for [ScheduleInterviews.py](ScheduleInterviews.py) - [link](https://github.com/YogeshSharma0"
  },
  {
    "path": "Thoughtworks/ScheduleInterviews.py",
    "chars": 4084,
    "preview": "from typing import List,Tuple\nimport datetime\n\ndef divideWorkingHours(start_time:datetime.datetime,\n                    "
  },
  {
    "path": "Twilio/DiskSpaceAnalysis.py",
    "chars": 690,
    "preview": "# Number of Computers: n = 4\n# Space = [8,2,4,6]\n# x = 2, The segment length\n\n# The free disk space of computers in each"
  },
  {
    "path": "Twilio/README.md",
    "chars": 423,
    "preview": "### Hackerrank Test - 2020  \n  \n1. Find the area of largest square that can be found with all 1's present in a binary ma"
  },
  {
    "path": "Uber/README.md",
    "chars": 2667,
    "preview": "## Questions on SQL:  \n\n1. Let's say there is a table called Completed_Trips. The fields present in the table are `rider"
  },
  {
    "path": "Uber/getNewArray.py",
    "chars": 822,
    "preview": "\"\"\"\nGiven an array of integers, return a new array such that each element at index i \nof the new array is the product of"
  },
  {
    "path": "Ushur/README.md",
    "chars": 239,
    "preview": "# Personal Experience:  \n## First round - Hackerearth Test 2021 (Data Analytics Engineer):  \n+ Fairly simple coding ques"
  },
  {
    "path": "Ushur/findPairs.py",
    "chars": 548,
    "preview": "\"\"\"\nGiven a list of numbers and each number represents a different color of\na sock, Find the number of pairs that can be"
  },
  {
    "path": "VMWare/Convert_Infix_To_Postfix.py",
    "chars": 1643,
    "preview": "{\n#Initial Template for Python 3\nimport atexit\nimport io\nimport sys\n# This code is contributed by Nikhil Kumar Singh(nic"
  },
  {
    "path": "VMWare/maxIndexDiffOfArray.py",
    "chars": 722,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "VMWare/mergeKSortedLinkedLists.py",
    "chars": 2712,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Vimeo/README.md",
    "chars": 635,
    "preview": "# Senior Data Engineer: Interview Process For Vimeo - 2024:  \n## First Round (Format):  \n+ Coding Test with Interviewers"
  },
  {
    "path": "Visa/addNode_DoublyLinkedList.py",
    "chars": 1836,
    "preview": "{\nclass Node:\n\tdef __init__(self, data):\n\t\tself.data = data\n\t\tself.next = None\n\t\tself.prev = None\nclass DoublyLinkedList"
  },
  {
    "path": "Visa/populateList.py",
    "chars": 832,
    "preview": "\"\"\"\nPopulate the list according to following fashion\n\nGiven a list of elements [a0, a1, a2, ......, an-1] of length n\n\nR"
  },
  {
    "path": "Visa/removeDuplicatesSortedLinkedList.py",
    "chars": 2380,
    "preview": "{\n#Initial Template for Python 3\n#Contributed by : Nagendra Jha\nimport atexit\nimport io\nimport sys\n_INPUT_LINES = sys.st"
  },
  {
    "path": "Walmart/GroupAnagrams.py",
    "chars": 2061,
    "preview": "## Data Engineering Interview at Walmart\n\n# Find the words from the given list and group them with the words which are \n"
  },
  {
    "path": "Walmart/minimumCoins.py",
    "chars": 1224,
    "preview": "# Given a value V, if we want to make a change for V cents, and we have a finite supply of \n# each of C = { C1, C2, .., "
  },
  {
    "path": "Walmart/minimumCoinsRecursive.py",
    "chars": 1128,
    "preview": "# Given a value V, if we want to make a change for V cents, and we have an infinite supply of \n# each of C = { C1, C2, ."
  },
  {
    "path": "Yahoo/ThreeWayPartition.py",
    "chars": 1707,
    "preview": "{\n# Driver Program\nfrom collections import Counter\nif __name__=='__main__':\n    t = int(input())\n    for i in range(t):\n"
  },
  {
    "path": "ZSAssociates/CrossSequence.py",
    "chars": 696,
    "preview": "\"\"\"\nGiven an array A, Integer K\n\nFind the Kth Smallest element of array which is generated from\ncalculating the absolute"
  },
  {
    "path": "ZSAssociates/OutputOfProgram.py",
    "chars": 618,
    "preview": "import pandas as pd\nfrom pyspark import SparkContext\nfrom pyspark.sql.functions import col,struct,pandas_udf,PandasUDFTy"
  },
  {
    "path": "ZSAssociates/OutputOfProgram2.py",
    "chars": 744,
    "preview": "def MainProgram(iterable, x):\n    sample = tuple(iterable)\n    n = len(sample)\n    if not n and x:\n        return\n    in"
  },
  {
    "path": "Zoho/merge2SortedLinkedLists.py",
    "chars": 2419,
    "preview": "{\n#Initial Template for Python 3\n# Node Class\nclass Node:\n    def __init__(self, data):   # data -> value stored in node"
  },
  {
    "path": "Zoho/rearrangeArrayAlternately.py",
    "chars": 923,
    "preview": "{\n#Initial Template for Python 3\nimport math\ndef main():\n        T=int(input())\n        while(T>0):\n            \n       "
  },
  {
    "path": "Zycus/README.md",
    "chars": 1779,
    "preview": "# Personal Experience (Interview Process for AI/Machine Learning Engineer - 2020):  \n### First screening round:  \n+ Inte"
  },
  {
    "path": "cimpress/README.md",
    "chars": 2332,
    "preview": "Interview Process for Data Engineer - 2021 (Personal Experience):  \n===================================================="
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the absognety/Interview-Process-Coding-Questions GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 156 files (243.8 KB), approximately 72.0k tokens, and a symbol index with 320 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!