├── Apple Jr. Python Developer ├── README.md └── questionSix.py ├── BNY Mellon Backend Software Developer ├── README.md ├── images │ ├── Q6E1.JPG │ ├── Q6E2.JPG │ └── Wikipedia.JPG ├── isJson.py ├── noOfPaths.py ├── replaceChars.py └── topicCount.py ├── BitGo Software Test Engineer ├── README.md └── firstChar.py ├── Borgwards Self Driving Car Engineer-2018 ├── README.md ├── Round - 1 - Technical Phone Interview │ └── README.md └── Round - 2 - Assignement │ ├── README.md │ └── image_rsrcs │ ├── KittiInference.png │ ├── KittiInference2.png │ ├── KittiInference3.png │ ├── carDetection1.png │ ├── carDetection2.png │ ├── carDetection3.png │ ├── kitti_data.png │ ├── problem.png │ └── semantic_segmentation.png ├── ClassPass 2019 Software Engineer New Grad ├── README.md └── planeSeats.py ├── Coursera Software Engineer Entry Level-2019-Part-1 ├── README.md ├── firstOccurence.py ├── images │ ├── CourseraQ1P1.JPG │ ├── CourseraQ1P2.JPG │ ├── CourseraQ1P3.JPG │ ├── CourseraQ2P1.JPG │ ├── CourseraQ2P2.JPG │ ├── Q1E1.JPG │ ├── Q1E2.JPG │ ├── Q1E3.JPG │ └── Q1E4.JPG └── maxLength.py ├── Coursera Software Engineer Entry Level-2019-Part-2 ├── README.md ├── palindrome.py └── triplets.py ├── Esri Deep Learning Engineer └── README.md ├── Google Software Engineer New Grad 2018 └── README.md ├── HARMAN International Software Engineer 2019 ├── README.md ├── codeDependency.py ├── dataDesignToStoreItems.py ├── missingNumber.py └── powerOfFour.py ├── INVIDI technologies Associate Software Developer 2019 ├── README.md └── stack.cpp ├── Jet.com (walmart company) Software Engineer - Big Data ├── README.md └── fourSum.py ├── LinkedIn Software Engineer - Entry Level ├── README.md ├── cutSticks.py └── simpleQuery.py ├── Orchestrade Financial Systems Software Engineer ├── README.md └── isDuplicate.py ├── QuantumBlack Machine Learning Software Engineer 2019 ├── Correlation.py ├── Images │ └── Correlation.JPG ├── README.md ├── numOfPairs.py └── simpleQuery.py ├── README.md ├── SAP Silicon Valley Next Talent Program 2019 ├── README.md ├── findDepth.py ├── findIndex.py └── moveZeros.py ├── Twilio Software Engineer - New Grad-Part-1 ├── README.md ├── input.txt ├── records_input.txt ├── reformateDate.py └── totalRequests.py ├── Twilio Software Engineer - New Grad-Part-2 ├── README.md ├── input.txt ├── missingWords.py ├── records_input.txt └── totalRequests.py ├── Twilio University Internship 2019 ├── README.md ├── distinctPairs.py ├── kSubseq.py └── stockAnalysis.py ├── TwoSigma Software Engineer Investments 2019 ├── README.md ├── Round 1 - Hackerrank Online Assessment │ ├── README.md │ ├── friendCircle.py │ └── longestChain.py ├── Round 2 - HR Interview │ └── README.md └── Round 3 - Technical Phone Interview │ ├── README.md │ └── maximumSumCircularSubArray.py ├── VISA Senior Software Engineer 2019 ├── README.md ├── Round - 1 - Hackerrank Online Assessment │ ├── README.md │ ├── flowerBouquets.py │ ├── images │ │ ├── BinaryJumpsExample.JPG │ │ └── FlowerBouquets.JPG │ ├── maxStreak.py │ └── powerJump.py ├── Round - 2 - Coding Phone Interview │ ├── README.md │ └── isBinarySearchTree.py └── Round - 3 - Onsite │ └── Design Elevator │ └── elevator.py ├── Workday Senior Java Platform Developer ├── DistanceCalculator.java ├── ImageResources │ ├── Welcome.JPG │ ├── Workday_Q2_P1.JPG │ ├── Workday_Q2_P2.JPG │ ├── Workday_Q2_P3.JPG │ ├── Workday_Q3.JPG │ ├── Workday_Q4.JPG │ ├── Workday_Q5.JPG │ ├── Workday_Q6.JPG │ ├── Workday_Q7.JPG │ ├── Workday_Q8_P1.JPG │ ├── Workday_Q8_P2.JPG │ ├── Workday_Q8_P3.JPG │ ├── Workday_Q8_P4.JPG │ ├── Workday_Q9_P1.JPG │ ├── Workday_Q9_P2.JPG │ ├── Workday_Q9_P3.JPG │ ├── Workday_Q9_P3_expected.JPG │ ├── Workday_Q9_P4.JPG │ └── Workday_Q9_P5_expected.JPG ├── TipTop.java ├── counts.py ├── degreeOfArray.py └── regEx.py └── Workday Software Development Engineer ├── README.md └── reductionCost.py /Apple Jr. Python Developer/README.md: -------------------------------------------------------------------------------- 1 | # HireVue 2 | 3 | ## Question 1 of 7 4 | 5 | This position is a 12 month contract at Apple in Sunnyvale CA. 6 | Apple is seeking a Python Developer to update existing and implement new utility commands for our Client environment. 7 | These self-contained utility commands are exposed to our Client users and perform custom functions not provided by Client, such as: 8 | conversion of data records integrate with ticketing systems, integrate with chat bots, enriching data records with external info, exchange data with other internal systems. 9 | 10 | does this fir you skill set 11 | 12 | Select Yes or No 13 | 14 | 15 | 16 | ## Question 2 of 7 17 | 18 | How does your experience and knowledge fit for this role at Apple ? (Record a video response) 19 | 20 | 21 | 22 | ## Question 3 of 7 23 | 24 | What are key features of Python? (Record a video response) 25 | 26 | ## Question 4 of 7 27 | 28 | What is your experience with enriching data records with external information(for example GeoIP details)? 29 | If no experience in this, do you have similar experience? (Record a video response) 30 | 31 | ## Question 5 of 7 32 | 33 | What is pickling and unpickling? (Record a video response) 34 | 35 | ## Question 6 of 7 36 | 37 | 38 | Write a program: 39 | 40 | Programming Challenge Description: 41 | The goal of this challenge is to design a cash register program. 42 | You will be given two decimal numbers. The first is the purchase price (PP) of the item. 43 | The second is the cash (CH) given by the customer. 44 | Your register currently has the following bills/coins within it: 45 | 'PENNY': .01, 46 | 'NICKEL': .05, 47 | 'DIME': .10, 48 | 'QUARTER': .25, 49 | 'HALF DOLLAR': .50, 50 | 'ONE': 1.00, 51 | 'TWO': 2.00, 52 | 'FIVE': 5.00, 53 | 'TEN': 10.00, 54 | 'TWENTY': 20.00, 55 | 'FIFTY': 50.00, 56 | 'ONE HUNDRED': 100.00 57 | 58 | The aim of the program is to calculate the change that has to be returned to the customer. 59 | 60 | Input: 61 | Your program should read lines of text from standard input. 62 | Each line contains two numbers which are separated by a semicolon. 63 | The first is the Purchase price (PP) and the second is the cash(CH) given by the customer. 64 | 65 | Output: 66 | For each line of input print a single line to standard output which is the change to be returned to the customer. 67 | In case the CH < PP, print out ERROR. If CH == PP, print out ZERO. 68 | For all other cases print the amount that needs to be returned, in terms of the currency values provided. 69 | The output should be alphabetically sorted. 70 | 71 | Test 1 72 | Test Input : 15.94;16.00 73 | Expected Output : NICKEL,PENNY 74 | 75 | 76 | Test 2 77 | Test Input : Input17;16 78 | Expected Output : ERROR 79 | 80 | Test 3 81 | Test Input : 35;35 82 | Expected Output : ZERO 83 | 84 | 85 | Test 4 86 | Test Input : 45;50 87 | Expected Output : FIVE 88 | 89 | 90 | ## Question 7 of 7 91 | 92 | How did you solve the challenge ? (Record a video response) 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /Apple Jr. Python Developer/questionSix.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def solution(actual_price, given_price): 5 | if given_price < actual_price: 6 | print("ERROR") 7 | return 8 | elif given_price == actual_price: 9 | print("ZERO") 10 | return 11 | else: 12 | price_to_return = given_price - actual_price 13 | results = set([]) 14 | 15 | for value in values: 16 | while price_to_return >= value: 17 | results.add(value) 18 | price_to_return = price_to_return - value 19 | 20 | results = list(results) 21 | results = [name2value[result] for result in results] 22 | 23 | results = sorted(results) 24 | print(",".join(results)) 25 | return 26 | 27 | 28 | name2value = {.01: 'PENNY', .05: 'NICKEL', .10: 'DIME', .25: 'QUARTER', .50: 'HALF DOLLAR', 1.00: 'ONE', 2.00: 'TWO', 29 | 5.00: 'FIVE', 10.00: 'TEN', 20.00: 'TWENTY', 50.00: 'FIFTY'} 30 | 31 | values = [100, 50, 20, 10, 5, 2, 1, 0.50, 0.25, 0.10, 0.05, 0.01] 32 | 33 | for line in sys.stdin: 34 | purchase_price, cash = line.split(";") 35 | purchase_price, cash = float(purchase_price), float(cash) 36 | solution(purchase_price, cash) 37 | -------------------------------------------------------------------------------- /BNY Mellon Backend Software Developer/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | 4 | ## 1. Validate JSON 5 | ----- 6 | Your job is to determine if an input string is valid JSON. 7 | An easy resource for understanding JSON is here: http://www.json.org/ 8 | 9 | Your requirements: 10 | - Determine if the input string is valid JSON. 11 | - Return "true" if it is valid. Return "false" if it is not. 12 | 13 | Example: 14 | 15 | If you are given the following input data: 16 | `{"test": "Hello World"}` 17 | 18 | 19 | The output will be: 20 | `true` 21 | 22 | On the other hand, if you are given the following input data: 23 | `{"test": Hello World"}` 24 | 25 | The output will be: 26 | `false` 27 | 28 | 29 | 30 | ## 2. HTML Entity Codes 31 | ----- 32 | 33 | ## Background 34 | When working with item like HTML and XML, you often want to use replacements for normal characters. 35 | In HTML, these are often called referenced "entities". 36 | 37 | 38 | ## Problem 39 | You will need to do a limited version of character replacement. 40 | Specifically, you need to find these characters in an input string: 41 | 42 | - "<" 43 | - ">" 44 | - "&" 45 | 46 | and replace them with: 47 | 48 | - "<" 49 | - ">" 50 | - "&" 51 | 52 | ## Example 53 | 54 | For example, if you are given this string: 55 | `Hello Goodbye & World` 56 | The output would be: 57 | `Hello < World > Goodbye & World` 58 | 59 | 60 | ## Considerations 61 | 62 | - Replace all of the characters 63 | - Your code should be able to handle Unicode characters (i.e., non-English) 64 | 65 | 66 | ## 3. Wikipedia Article 67 | ----- 68 | 69 | In this challenge, use an **HTTP GET** method to retrieve information from Wikipedia. 70 | Query https://en.wikipedia.org/w/api.php?action=parse§ion=0&prop=text&format=json&page=[topic] to get the topic Wikipedia article. 71 | Return the total number of times that the string [topic] appears in the article's text field. 72 | Note that the search is case-sensitive. 73 | 74 | The query response from the website is a JSON object described below: 75 | - parse: A JSON object representing the article's parsed web page. It has following three fields: 76 | 1. title: The article's title, as specified by the argument passed as topic. 77 | 2. pageid: The article's Page ID. 78 | 3. text: A JSON object that contains the Wikipedia article as an HMTL dump. 79 | 80 | **Function Description:** 81 | 82 | Complete the function `getTopicCount` in the editor below. 83 | The function must return an integer, the number of times the search term topic appears in the returned text field. 84 | 85 | `getTopicCount` has the following parameter(s): 86 | topic: a string to query 87 | 88 | 89 | [image0]: ./images/Wikipedia.JPG "Wikipedia" 90 | ![Wikipedia][image0] 91 | 92 | 93 | ## 4. Loading a web page 94 | ----- 95 | 96 | Imagine you just purchased a new computer, and you've opened up a web browser for the first time. 97 | You go to the address bar type in: 98 | `https://example.org` 99 | 100 | Describe what happens between the moment you press the `Enter` key when the page has finished loading in the browser. 101 | 102 | Note: this is an open-ended question. You will need to decide the level of detail you want to include. 103 | 104 | 105 | Ans: 106 | - When the user hits enter, the browser looks in the cache whether the corresponding IP address is present or not. 107 | - If the IP is present in the browser cache then it renders the page from the cache. 108 | - If IP is not present in the browser cache then it will try to find the IP for the corresponding URL in the DNS server. 109 | - Once the browser gets the IP from DNS server, it will establish a connection and send the HTTP request to the server with that IP. 110 | - The server will serve the browser by checking the URL and responding with HTTP response. 111 | - The browser receives the HTTP response which is usually an HTML page which browser then renders the response in the window.  112 | 113 | 114 | ## 5. Complexity of the Code Snippet 115 | ----- 116 | 117 | Consider the following code snippet: 118 | 119 | int a = 1; 120 | while (a": ">", "&": "&"} 4 | results = "" 5 | for i in range(len(original)): 6 | if original[i] in mapping: 7 | results += mapping[original[i]] 8 | else: 9 | results += original[i] 10 | return results 11 | -------------------------------------------------------------------------------- /BNY Mellon Backend Software Developer/topicCount.py: -------------------------------------------------------------------------------- 1 | # Complete the function below. 2 | 3 | 4 | import urllib.request 5 | 6 | def getTopicCount(topic): 7 | url = "https://en.wikipedia.org/w/api.php?action=parse§ion=0&prop=text&format=json&page=" 8 | contents = urllib.request.urlopen(url+topic).read().decode('utf-8') 9 | count = 0 10 | pos = contents.find(topic) 11 | while pos != -1: 12 | count += 1 13 | pos = contents.find(topic, pos+1) 14 | return count 15 | 16 | print(getTopicCount("pizza")) 17 | -------------------------------------------------------------------------------- /BitGo Software Test Engineer/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | 4 | ## 1.FirstIndex of Character 5 | ----- 6 | Given a string and a character. Find the first index of the character in the string 7 | 8 | Example: 9 | 10 | If you are given the following input data: 11 | `string = "hi, this is bitgo test"` 12 | `character = "t"` 13 | 14 | The output will be: 15 | `4` 16 | 17 | 18 | 19 | 20 | ## 2. What happens when you type a url in the browser and hit enter 21 | ----- 22 | 23 | 24 | ## 3. Testing 25 | ------ 26 | 27 | Write unit and integration test cases for transaction api. -------------------------------------------------------------------------------- /BitGo Software Test Engineer/firstChar.py: -------------------------------------------------------------------------------- 1 | # Complete the checkJSON function below. 2 | 3 | def solution(string, character): 4 | for idx, char in enumerate(string): 5 | if char == character: 6 | return idx 7 | return -1 8 | 9 | res = solution("hi, this is bitgo test", "t") 10 | print(res) 11 | -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/README.md: -------------------------------------------------------------------------------- 1 | ## Interview Description 2 | ---- 3 | - At this point of time I have cleared two interview rounds of VISA, Inc. 4 | 5 | ## Round 1 (Phone Interview) 6 | --- 7 | - The phone interview was 45 minutes 8 | - I was asked question on neural networks 9 | 10 | 11 | ## Round 2 (Assignment) 12 | --- 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 1 - Technical Phone Interview/README.md: -------------------------------------------------------------------------------- 1 | ## Technical Phone Interview 2 | ---- 3 | 4 | 1. What is overfitting? 5 | Ans. 6 | - Model remembering the training data and not performing well on the test data is called overfitting. 7 | 8 | 2. When do you know overfitting has occurred without looking at the test data? 9 | Ans. 10 | - We can use validation set to see if the model overfits the training data. 11 | - If validation error graph is more then training error graph then model overfits the training data. 12 | 13 | 14 | 3. How to prevent over-fitting? 15 | Ans. 16 | - We can prevent over-fitting by regularization. 17 | 18 | 19 | 4. What are the types of regularization? 20 | Ans. 21 | - Dropouts and L2 regularization are some types of regularizations 22 | 23 | 5. What are Dropouts? 24 | Ans. 25 | - The signal from some of the nodes are skipped. 26 | - This prevents weights from exploding or having higher value. 27 | 28 | 6. What is batch-normalization? 29 | Ans. 30 | - batch-normalization is a normalization of the batch data being processed 31 | - If the data in it's raw format is normalized to get good results then same is the idea to normalize the data in the intermediary layers 32 | 33 | 7. Why do we use batch-normalization? 34 | Ans. 35 | - It helps in reducing the training time and getting fast towards the global minima. -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/README.md: -------------------------------------------------------------------------------- 1 | ## Challenge Description 2 | ---- 3 | 4 | # Solution: 5 | ---- 6 | https://github.com/jayshah19949596/BorgWards-Vehicle-Detection-Challenge 7 | 8 | ### Introduction to Challenge 9 | ---- 10 | - This coding test does not necessarily reflect or indicate what we are working on at Borgward R&D Silicon Valley.- - The test is just to provide a way for us to estimate our candidate’s coding skills 11 | - We are not looking for the exact correct answer or solutions, we are more looking for the way how you solve this problem, the way how you code, code style, code formality, code efficiencies, and most importantly the innovative thinking & ideas that you express in your algorithms. 12 | - Please do NOT spend more than 2 hours on this test, and try your best to finish the test with most efficient and practical code. 13 | 14 | ### Problem 15 | ---- 16 | - BDD100K is a large-scale diverse driving video database: http://bair.berkeley.edu/blog/2018/05/30/bdd/. There are different tasks of perception algorithms such as object detection, semantic segmentations, lane detections that can be developed and tested using this dataset. 17 | - Let's now focus on one task called semantic segmentation. Semantic segmentation is so called "dense" prediction problem, where predictions are demanded at per pixel level. 18 | - Segmentation algorithms usually involves deep neural network, with approaches such as "encoder-decoder" architectures, "dilated convolutional layers", "multi-scale receptive field", so on and so forth. 19 | - We are not going to ask you to code a DNN model to perform semantic segmentation of course for an interview test. Instead, we are working some handy tools as shown below in the figure: we need some code or algorithms to draw a bounding box around "car" or "vehicle pixels", in the example figure below, we have two cars in the raw image on the left, and assuming a prefect semantic segmentation DNN can give you a semantic map as shown on the right, we want to detect the boundaries or bounding boxes for the two vehicles, white small vehicle on the left, and the red big SUV on the right. 20 | 21 | [image1]: ./image_rsrcs/problem.png "Problem" 22 | ![Problem][image1] 23 | 24 | - Of course, this tasks is getting more and more challenging when vehicles have a lot of overlap on the image and shape becomes difficult to distinguish between different vehicles, but to get started we can assume the overlap is not huge. 25 | - You can use any programming language that you are comfortable with (c++, python preferred), and we'd prefer you code the algorithm yourself instead of calling a library such as OpenCV. 26 | - If you need some small sample data to test the code, we have a few images here from BDD100K: https://borgward.atlassian.net/wiki/spaces/BORPub/pages/655369/Public+Available+Dataset you can download the tar ball for the small sample dataset. 27 | 28 | ## My Solution 29 | ---- 30 | 31 | 32 | ### Semantic Segmentation on Kitti 33 | ---- 34 | - I have choosen Kitti Dataset for Vehicle Detection. you can find the description of dataset [here](http://www.cvlibs.net/datasets/kitti/eval_semseg.php?benchmark=semantics2015) 35 | - I have tried to replicate [Fully Convolution Network](https://people.eecs.berkeley.edu/~jonlong/long_shelhamer_fcn.pdf) 36 | - I have used a pretrained VGG16 Model as Encoder and in Decoder I have used Transpose Convolution with Skip Connections from the encoder 37 | - Download VGG16 from [here](http://s3-us-west-1.amazonaws.com/udacity-selfdrivingcar/vgg.zip) 38 | - Extract the contents of the VGG in the "./data/vgg_model" folder 39 | - This network is used for Semantic Segmentation whose architecture is below: 40 | 41 | [image2]: ./image_rsrcs/semantic_segmentation.png "SemanticSegmentation" 42 | ![SemanticSegmentation][image2] 43 | 44 | 45 | - Training image and its corresponding Ground Truth: 46 | 47 | [image3]: ./image_rsrcs/kitti_data.png "KittiData" 48 | ![KittiData][image3] 49 | 50 | 51 | ### Semantic Segmentation Results 52 | ---- 53 | [image4]: ./image_rsrcs/KittiInference.png "KittiInference" 54 | ![KittiInference][image4] 55 | 56 | [image5]: ./image_rsrcs/KittiInference2.png "KittiInference2" 57 | ![KittiInference2][image5] 58 | 59 | 60 | [image6]: ./image_rsrcs/KittiInference3.png "KittiInference3" 61 | ![KittiInference3][image6] 62 | 63 | 64 | ### Object Detection 65 | ---- 66 | 67 | ### Object Detection with Tensorflow API 68 | ---- 69 | - Used TensorFlow's Pretrained SSD model fro detecting Cars 70 | - This model is capable of performing object detecting in real time which is faster than Semantic Segmentation 71 | - Link to TensorFlow Object Detection Api is [here](https://github.com/tensorflow/models/tree/master/research/object_detection) 72 | - This model is used to detect cars on this data: https://borgward.atlassian.net/wiki/spaces/BORPub/pages/655369/Public+Available+Datase 73 | 74 | 75 | ### Results 76 | ---- 77 | [image7]: ./image_rsrcs/carDetection1.png "carDetection1" 78 | ![carDetection1][image7] 79 | 80 | [image8]: ./image_rsrcs/carDetection2.png "carDetection2" 81 | ![carDetection2][image8] 82 | 83 | 84 | [image9]: ./image_rsrcs/carDetection3.png "carDetection3" 85 | ![carDetection3][image9] 86 | 87 | 88 | -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/KittiInference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/KittiInference.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/KittiInference2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/KittiInference2.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/KittiInference3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/KittiInference3.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/carDetection1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/carDetection1.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/carDetection2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/carDetection2.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/carDetection3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/carDetection3.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/kitti_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/kitti_data.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/problem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/problem.png -------------------------------------------------------------------------------- /Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/semantic_segmentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Borgwards Self Driving Car Engineer-2018/Round - 2 - Assignement/image_rsrcs/semantic_segmentation.png -------------------------------------------------------------------------------- /ClassPass 2019 Software Engineer New Grad/README.md: -------------------------------------------------------------------------------- 1 | # Online Assessment 2 | 3 | ## 1. Plane Seats 4 | ----- 5 | 6 | - Given a list of reserved seats on a plane, find the number of three-person families you can fit together in the unreserved seats. 7 | - `2C` and `2D` are asile seats which are not in continuation 8 | -------------------------------------------------------------------------------- /ClassPass 2019 Software Engineer New Grad/planeSeats.py: -------------------------------------------------------------------------------- 1 | def solve(n, s): 2 | seats1 = ["A", "B", "C"] 3 | seats2 = ["D", "E", "F", "G"] 4 | seats3 = ["J", "L", "I"] 5 | 6 | s_list = s.plit() 7 | reserved = set([]) 8 | for i in range(len(s_list)): 9 | reserved.add(s_list[i]) 10 | 11 | count = 0 12 | for i in range(1, n + 1): 13 | num = str(i) 14 | if (num+seats1[0] not in reserved) and (num+seats1[1] not in reserved) and (num+seats1[2] not in reserved): 15 | count += 1 16 | 17 | if (num+seats3[0] not in reserved) and (num+seats3[1] not in reserved) and (num+seats3[2] not in reserved): 18 | count += 1 19 | 20 | if (num+seats2[0] not in reserved) and (num+seats2[1] not in reserved) and (num+seats2[2] not in reserved): 21 | count += 1 22 | elif (num+seats2[1] not in reserved) and (num+seats2[2] not in reserved) and (num+seats2[3] not in reserved): 23 | count += 1 24 | 25 | return count 26 | -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | 4 | ## 1. Find the Substring 5 | ----- 6 | We define the following: 7 | - String `s` consists of lowercase letters in the range ascii[a-z]. 8 | - String `x` consists of lowercase letters and may also contain a single wild-card character `*`, that represents any one character. 9 | 10 | Given `s` and `x`, we want to know the zero-based index of the first occurrence of `x` in `s`. 11 | For example, if `s = xabcdey` and `x = ab*de`, the index is `1`. 12 | 13 | [image1]: ./images/Q1E1.JPG "Question 1 Example 1" 14 | ![Question 1 Example 1][image1] 15 | 16 | Function Description: 17 | Complete the function `firstOccurence` in the editor below. 18 | The function must return an integer denoting the zero-based index of the first occurrence of string `x` in `s`. 19 | If `x` is not in `s` return `-1` instead. 20 | 21 | `firstOccurence` has the following parameter(s): 22 | `s`: a string of lowercase letters. 23 | `x`: a string of lowercase letter which may contain 1 instance of wild-card character `*` 24 | 25 | 26 | Constraints: 27 | - 1 <= |s| <= 500000 28 | - 1 <= |x| <= 1000 29 | 30 | Input Format for Custom Testing: 31 | Input from stdin will be processed as follows and passed to the function. 32 | 33 | The first line contains the string `s`. 34 | The second line contains the string `x`. 35 | 36 | 37 | Sample Input 0: 38 | juliasamanthantjulia 39 | ant 40 | 41 | Sample Output 0: 42 | 8 43 | 44 | Explanation 0: 45 | 46 | [image2]: ./images/Q1E2.JPG "Question 1 Example 2" 47 | ![Question 1 Example 2][image2] 48 | 49 | Sample Input 1: 50 | juliasamanthhasamanthajulia 51 | has 52 | 53 | Sample Output 1: 54 | 11 55 | 56 | Explanation 1: 57 | 58 | [image3]: ./images/Q1E3.JPG "Question 1 Example 3" 59 | ![Question 1 Example 3][image3] 60 | 61 | 62 | Sample Input 2: 63 | juliasamanthhasamanthajulia 64 | ant*as 65 | 66 | Sample Output 2: 67 | 8 68 | 69 | Explanation 2: 70 | 71 | [image4]: ./images/Q1E4.JPG "Question 1 Example 4" 72 | ![Question 1 Example 4][image4] 73 | 74 | 75 | 76 | ## 2. Longest Subarray 77 | ----- 78 | We define a subarray of array `a` to be a contiguous block of `a's` elements having a length that is less than or equal to the length of array `a`. 79 | For example, the subarrays of array `a = [1, 2, 3]` are `[1], [2], [3], [1, 2], [2, 3] and [1, 2, 3]`. 80 | Now, let's say we have an integer `k = 3`. 81 | The subarrays of array `a` having elements that sum to a number <= `k` are `[1], [2], and [1, 2]`. 82 | The longest of these subarrays is `[1, 2]`, which has a length of 2. 83 | 84 | 85 | 86 | Function Description: 87 | Complete the function `maxLength` in the editor below. 88 | 89 | 90 | `maxLength` has the following parameter(s): 91 | 1. An array of integers `a`. 92 | 2. An integer, `k`. 93 | 94 | 95 | The function must return the length of the longest subarray having elements that sum to a number less than or equal to k. 96 | You can not reorder the array's elements. 97 | 98 | 99 | Constraints: 100 | - 1 <= n <= 10000 101 | - 1 <= a[i] < 10^3 102 | - 1 < k < 10^9 103 | 104 | 105 | Input Format: 106 | Locked stub coee in the editor reads the following input from stdin and passes it to the function: 107 | The first line contains a single integer, `n`, denoting the number of elements in array `a`. 108 | Each line `i` of the `n` subsequent lines (where 0 <= i <= n) contains an integer describing element `i` in array `a`. 109 | The laast line contains an integer, `k`. 110 | 111 | Output Format: 112 | The function must return the length of the longest subarray having a sum less than or equal to `k`. 113 | This is printed to stdout by locked stub coede in the editor. 114 | 115 | Sample Input 0: 116 | 3 117 | 1 118 | 2 119 | 3 120 | 4 121 | 122 | Sample Output 0: 123 | 2 124 | 125 | Explanation 0: 126 | The subarrays of [1, 2, 3] having elements that sum to a number <= (k = 4) are [1], [2], [3] and [1, 2]. 127 | The longest of these is [1, 2], which has a length of 2. 128 | Thus, we return 2 as our answer. 129 | 130 | Sample Input 1: 131 | 4 132 | 3 133 | 1 134 | 2 135 | 1 136 | 4 137 | 138 | Sample Output 0: 139 | 3 140 | 141 | Explanation 0: 142 | The subarrays of [3, 1, 2 , 1] having elements that sum to a number <= (k = 4) are [3], [1], [2], [1], [3, 1], [1, 2], [2, 1] and [1, 2, 1], which has a length of 3. 143 | The longest of these is [1, 2, 1], which has a length of 2. 144 | Thus, we return 3 as our answer. 145 | 146 | 147 | -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/firstOccurence.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'firstOccurrence' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts following parameters: 6 | # 1. STRING s 7 | # 2. STRING x 8 | # 9 | 10 | 11 | def firstOccurrence(s, x): 12 | # Write your code here 13 | xi = 0 14 | for idx, char in enumerate(s): 15 | if x[xi] == "*" or char == x[xi]: 16 | xi += 1 17 | if xi == len(x): 18 | return idx-len(x)+1 19 | else: 20 | xi = 0 21 | return -1 22 | -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ1P1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ1P1.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ1P2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ1P2.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ1P3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ1P3.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ2P1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ2P1.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ2P2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/CourseraQ2P2.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E1.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E2.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E3.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Coursera Software Engineer Entry Level-2019-Part-1/images/Q1E4.JPG -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-1/maxLength.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'maxLength' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts following parameters: 6 | # 1. INTEGER_ARRAY a 7 | # 2. INTEGER k 8 | # 9 | 10 | 11 | def maxLength(a, k): 12 | # Write your code here 13 | summ = count = max_count = 0 14 | for i in range(len(a)): 15 | if k >= summ+a[i]: 16 | summ += a[i] 17 | count += 1 18 | elif summ != 0: 19 | summ = summ - a[i-count] + a[i] 20 | max_count = max(count, max_count) 21 | return max_count 22 | -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-2/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | - I was given 60 minutes to solve the two questions. 4 | 5 | ## 1. Sub-palindrome 6 | ----- 7 | A palindrome is a string that reads the same forward and backward e.g. `121` or `tacocat`. 8 | A substring is a contiguous subset of characters in a string. 9 | Given a string `s`, how many distinct substring of s are palindrome. 10 | 11 | For example, `s = mokkari`. 12 | Its distinct palindromic substrings are `[m, a, k, r, i, kk, akka]`. 13 | 14 | Function Description: 15 | Complete the function `palindrome in the editor below. 16 | The function must return the number of distinct palindromes as in integer. 17 | 18 | 19 | `palindrome` has the following parameter(s): 20 | s: a string. 21 | 22 | Constraints: 23 | - 1 <= |s| <= 5000 24 | - Each character `s[i]` belongs `ascii[a-z]` 25 | 26 | 27 | 28 | Sample Input 0: 29 | s = aabaa 30 | 31 | Sample Output 0: 32 | 5 33 | 34 | Explanation 0: 35 | Palindromic substring are [a, aa, aabaa, aba, b] 36 | The substring "a" occurs 4 times, but is counted only once. 37 | Similarly, "aa" occurs twice but counts as one distinct palindrome. 38 | 39 | 40 | ## 2. Triplets 41 | ----- 42 | Given an array of `n` distinct integers, `d = [d[0], d[1], ..., d[n-1]]`, and an integer threshold `t`, how many `(a, b, c)` index triplets exist that satisfy both of the followings conditions? 43 | - `d[a] < d[b] < d[c]` 44 | - `d[a] + d[b] + d[c] <= t` 45 | 46 | For example, given the array `d = [1, 2, 3, 4, 5]` and threshold `t = 8`, the following triplets satisfy the constraints: 47 | 48 | (1, 2, 3) => 1 + 2 + 3 = 6 <= 8 49 | (1, 2 ,4) => 1 + 2 + 4 = 7 <= 8 50 | (1, 2, 5) => 1 + 2 + 5 = 8 <= 8 51 | (1, 3, 4) => 1 + 3 + 4 = 8 <= 8 52 | 53 | Function Description: 54 | Complete the function `triplets` in the editor below. 55 | The function must return a long integer denoting the number of triplets of (a, b, c) triplets satisfying the given conditions. 56 | 57 | 58 | `triplets` has the following parameter(s): 59 | t: an integer threshold. 60 | d[d[0], ..., d[n-1]]: an array of integers. 61 | 62 | Constraints: 63 | - 1 <= n <= 10000 64 | - 0 <= d[i] < 10^9 65 | - 0 < t < 3x10^9 66 | 67 | Input Format: 68 | Input from stdin will be processes as follows and passed to the function 69 | The first line contains the integer `t`. 70 | The second line contains an integer `n`, the size og the array d. 71 | Each of the next `n` lines contains an integer `d[i]` where 0 <= i <= n. 72 | 73 | 74 | Sample Input 0: 75 | 8 76 | 5 77 | 1 78 | 2 79 | 3 80 | 4 81 | 5 82 | 83 | Sample Output 0: 84 | 3 85 | 86 | Explanation 0: 87 | Given t=8 and d = [1, 2, 3, 4, 6] the following triplets satisfy the conditions: 88 | 1. (0, 1, 2) =>. 1 + 2 + 3 <= 8 89 | 2. (0, 1, 3) =>. 1 + 2 + 4 <= 8 90 | 3. (0, 2, 3) =>. 1 + 3 + 4 <= 8 91 | -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-2/palindrome.py: -------------------------------------------------------------------------------- 1 | def palindrome(s): 2 | n = len(s) 3 | ans = set([]) 4 | for center in range(2*n - 1): 5 | left = center / 2 6 | right = left + center % 2 7 | while left >= 0 and right < n and s[left] == s[right]: 8 | ans.add(s[left: right+1]) 9 | left -= 1 10 | right += 1 11 | return len(ans) 12 | -------------------------------------------------------------------------------- /Coursera Software Engineer Entry Level-2019-Part-2/triplets.py: -------------------------------------------------------------------------------- 1 | def bin_search(arr, target, start): 2 | left, ryt = start, len(arr)-1 3 | while left= start and left <= ryt: 4 | mid = (left+ryt)//2 5 | if arr[mid] == target: 6 | return mid 7 | elif arr[mid] > target: 8 | ryt = mid-1 9 | else: 10 | left = mid+1 11 | return left 12 | 13 | 14 | def tripletsSorting(nums, t): 15 | # TimeComplexity = O((n^2)logn) 16 | nums.sort() 17 | count = 0 18 | for i in range(len(nums)): 19 | for j in range(i+1, len(nums)): 20 | target = t - nums[i] - nums[j] 21 | if target < 0: 22 | break 23 | k = bin_search(nums, target, j+1) 24 | if k < len(nums) and nums[k] <= target: 25 | count += (k-j) 26 | elif k <= len(nums): 27 | count += (k-j-1) 28 | print(count) 29 | return count 30 | 31 | 32 | def triplets(arr, t): 33 | # TimeComplexity = O((n^3)) 34 | count = 0 35 | sets = set([]) 36 | for i in range(len(arr)): 37 | for j in range(len(arr)): 38 | if j == i: 39 | continue 40 | for k in range(len(arr)): 41 | if k == j or k == i or i == j: 42 | continue 43 | summ = (arr[i] + arr[j] + arr[k]) 44 | if frozenset((arr[i], arr[j], arr[k])) not in sets and summ <= t: 45 | sets.add(frozenset((arr[i], arr[j], arr[k]))) 46 | count += 1 47 | print(count) 48 | return count 49 | 50 | 51 | def tripletsSortWithPruning(arr, t): 52 | # TimeComplexity = O((n^3)) 53 | count = 0 54 | arr = sorted(arr) 55 | results = [] 56 | for i in range(len(arr)): 57 | if arr[i] >= t: 58 | break 59 | for j in range(i+1, len(arr)): 60 | if arr[i] + arr[j] >= t: 61 | break 62 | for k in range(j+1, len(arr)): 63 | currentSum = arr[i] + arr[j] + arr[k] 64 | if currentSum <= t: 65 | results.append([arr[i], arr[j], arr[k]]) 66 | count += 1 67 | else: 68 | break 69 | print("results =", results) 70 | print(count) 71 | return count 72 | 73 | 74 | array = [1, 2, 3, 4, 5] 75 | threshold = 8 76 | tripletsSorting(array, threshold) 77 | triplets(array, threshold) 78 | tripletsSortWithPruning(array, threshold) 79 | print("============") 80 | 81 | array = [1, 2, 3, 4, 6, 9] 82 | threshold = 8 83 | tripletsSorting(array, threshold) 84 | triplets(array, threshold) 85 | tripletsSortWithPruning(array, threshold) 86 | print("============") 87 | 88 | 89 | array = [1, 2, 3, 4, 6, 5] 90 | threshold = 11 91 | tripletsSorting(array, threshold) 92 | triplets(array, threshold) 93 | tripletsSortWithPruning(array, threshold) 94 | print("============") 95 | -------------------------------------------------------------------------------- /Esri Deep Learning Engineer/README.md: -------------------------------------------------------------------------------- 1 | ## Technical Phone Interview 2 | ---- 3 | 4 | 1. What does the error graph indicate when training error is less then validation error? 5 | Ans. 6 | - The model is over-fitting the training data. 7 | 8 | 2. How can you prevent over-fitting? 9 | Ans. 10 | - By regularization we can prevent over-fitting 11 | 12 | 3. What are dropouts? 13 | Ans. 14 | - Dropout is a type of over-fitting 15 | - Dropouts help in preventing over-fitting 16 | - Dropouts randomly skip the signal passing from the neurons. 17 | - Because of random skipping it helps in avoiding the weights to explode. 18 | 19 | 4. What is batch-normalization? 20 | Ans. 21 | - batch-normalization is a normalization of the batch data being processed 22 | - If the data in it's raw format is normalized to get good results then same is the idea to normalize the data in the intermediary layers 23 | 24 | 5. Importance of residual networks? 25 | Ans. 26 | - Residual Networks avoid over-fitting 27 | - Even with increasing the layers the Residual Networks avoid over-fitting 28 | 29 | 6. What is one hot encoding? 30 | Ans. 31 | - Transforming the data from raw to a vector which has only one value "1" and all other values "0" is called one hot encoding 32 | 33 | 34 | 7. Explain GAN? 35 | Ans. 36 | - GAN is a special neural networks. 37 | - It has two networks. One is the Generator network and other is the Discriminator network. 38 | - Generator tries to fool the Discriminator. 39 | - Discriminator tries to avoid fooling by Generator. 40 | - Both the network together achieve equilibrium where Discriminator network learns the distribution of the real data and produces data that is similar to that distribution. 41 | 42 | 8. What all networks have you implemented? -------------------------------------------------------------------------------- /Google Software Engineer New Grad 2018/README.md: -------------------------------------------------------------------------------- 1 | ## Interview Description 2 | ---- 3 | 4 | ## [Google Interview Part-1](https://medium.com/@jayshah_84248/google-interview-part-1-ed4f25634a81) 5 | --- 6 | - My ultimate preparation for Google phone interview is written in the above link. 7 | - All the resources that I was provided and I used is mentioned in the above link. 8 | 9 | ## [Google Interview Part-2](https://medium.com/@jayshah_84248/google-interview-part-2-c5f35633deda) 10 | --- 11 | - Dynamic Programming preparation for my Google interview is mentioned in the above link. 12 | - How I skipped my second phone interview to get a direct on-site interview. 13 | 14 | 15 | ## [Google Interview Part-3](https://medium.com/@jayshah_84248/google-interview-part-3-on-site-928b22b51139) 16 | - My ultimate preparation for Google on-site rounds is mention in the above link. 17 | - Leanring Advance algorithms and Advance Data Structures is mention in the above link. 18 | -------------------------------------------------------------------------------- /HARMAN International Software Engineer 2019/README.md: -------------------------------------------------------------------------------- 1 | # Round-2 WebEx Interview 2 | 3 | - I was asked to share my screen and open an editor and code. 4 | - It was an one hour interview. 5 | - I was asked the time complexity and space complexity of my code. 6 | - I was asked the following questions: 7 | 8 | 9 | 10 | ## 1. Data Structure design to Store Items 11 | --------- 12 | Given items and the name of the items as string and id of the items as integer. Design an efficient data structure to store items. Write a function to search an item by name. Write a function to search an item by id. 13 | 14 | ## 2. Code Dependency Check 15 | --------- 16 | Given pieces of code. Many code depends on other code. Determine the dependency of the code. 17 | 18 | ## 3. Power of four 19 | --------- 20 | Given an integer, write a function to check whether it is a power of 4. 21 | 22 | ## 4. Missing number 23 | --------- 24 | Given an array containing n distinct numbers taken from `0, 1, 2, ..., n` find the one that is missing from the array. 25 | -------------------------------------------------------------------------------- /HARMAN International Software Engineer 2019/codeDependency.py: -------------------------------------------------------------------------------- 1 | def dependency_check(code_id): 2 | seen = set([]) 3 | visited = set([]) 4 | dependency_list = [] 5 | topological_sort(code_id, dependency_list, visited, seen) 6 | return dependency_list 7 | 8 | 9 | def topological_sort(parent_code_id, dependency_list, visited, seen): 10 | if parent_code_id in visited: 11 | return 12 | 13 | visited.add(parent_code_id) 14 | seen.add(parent_code_id) 15 | 16 | for child_code_id in parent_code_id.children: 17 | if child_code_id in seen: 18 | print("Cyclic dependency present") 19 | topological_sort(child_code_id, dependency_list, visited, seen) 20 | 21 | seen.remove(parent_code_id) 22 | dependency_list.append(parent_code_id) 23 | -------------------------------------------------------------------------------- /HARMAN International Software Engineer 2019/dataDesignToStoreItems.py: -------------------------------------------------------------------------------- 1 | class DataStructure(object): 2 | def __init__(self): 3 | self.name2id = {} 4 | self.id2item = {} 5 | 6 | def add_item(self, item_name, item_id, item): 7 | self.name2id[item_name] = item_id 8 | self.id2item[item_id] = item 9 | 10 | def search_by_name(self, target_name): 11 | target_id = self.name2id[target_name] 12 | target_item = self.id2item[target_id] 13 | return target_item 14 | 15 | def search_by_id(self, target_id): 16 | target_item = self.id2item[target_id] 17 | return target_item 18 | -------------------------------------------------------------------------------- /HARMAN International Software Engineer 2019/missingNumber.py: -------------------------------------------------------------------------------- 1 | def missing_number(nums): 2 | arr = [0 for _ in range(len(nums))] 3 | 4 | for i in range(len(nums)): 5 | if nums[i] < len(nums): 6 | arr[nums[i]] = -1 7 | 8 | for i in range(len(nums)): 9 | if arr[i] != -1: 10 | return i 11 | 12 | return len(nums) -------------------------------------------------------------------------------- /HARMAN International Software Engineer 2019/powerOfFour.py: -------------------------------------------------------------------------------- 1 | def is_power_of_four(n): 2 | if n < 1: 3 | return False 4 | while n % 4 == 0: 5 | n /= 4 6 | return n == 1 7 | -------------------------------------------------------------------------------- /INVIDI technologies Associate Software Developer 2019/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in online challenge (C++ only) 2 | 3 | 4 | ## 1. Custom Stack 5 | ----- 6 | -------------------------------------------------------------------------------- /INVIDI technologies Associate Software Developer 2019/stack.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | 9 | int operation(string &S, std::stack &nums, string &word, int i){ 10 | int top_element; 11 | int num1, num2; 12 | 13 | if (i == S.size() || S.at(i) == ' '){ 14 | if (word == "DUP"){ 15 | // push the top of stack 16 | if (nums.size()>0){ 17 | top_element = nums.top(); 18 | nums.push(top_element); 19 | } 20 | else{ 21 | return -1; 22 | } 23 | } 24 | else if (word == "POP"){ 25 | if (nums.size()>0){ 26 | nums.pop(); 27 | } 28 | else{ 29 | return -1; 30 | } 31 | } 32 | else if (word == "+"){ 33 | if (nums.size()>1){ 34 | num1 = nums.top(); 35 | nums.pop(); 36 | num2 = nums.top(); 37 | nums.pop(); 38 | nums.push(num1+num2); 39 | } 40 | else{ 41 | return -1; 42 | } 43 | } 44 | else if (word == "-"){ 45 | if (nums.size()>1){ 46 | num1 = nums.top(); 47 | nums.pop(); 48 | num2 = nums.top(); 49 | nums.pop(); 50 | nums.push(num1-num2); 51 | } 52 | else{ 53 | return -1; 54 | } 55 | } 56 | else{ 57 | nums.push(stoi(word)); 58 | } 59 | word = ""; 60 | 61 | } 62 | 63 | else{ 64 | word = word+S.at(i); 65 | 66 | } 67 | 68 | return 0; 69 | } 70 | 71 | int solution(string &S) { 72 | int stop; 73 | unsigned i; 74 | string word = ""; 75 | std::stack nums; 76 | 77 | for(i=0; i= 0 and left<=ryt: 5 | mid = (left+ryt)//2 6 | if arr[mid] == target: 7 | return mid+1 8 | elif arr[mid]>target: 9 | ryt = mid-1 10 | else: 11 | left = mid+1 12 | return left 13 | 14 | def counts(nums, maxs): 15 | nums = sorted(nums) 16 | results = [] 17 | for maxi in maxs: 18 | count = bin_search(nums, maxi) 19 | results.append(count) 20 | return results 21 | 22 | 23 | arr = [1, 2, 4, 4, 7] 24 | maxes = [3, 5] 25 | res = counts(arr, maxes) 26 | print("numbers =", arr, "maxes =", maxes, "answer =", res) 27 | 28 | arr = [2, 10, 5, 4, 8] 29 | maxes = [3, 1, 7, 8] 30 | res = counts(arr, maxes) 31 | print("numbers =", arr, "maxes =", maxes, "answer =", res) 32 | 33 | arr = [1, 4, 2, 4] 34 | maxes = [3, 5] 35 | res = counts(arr, maxes) 36 | print("numbers =", arr, "maxes =", maxes, "answer =", res) 37 | -------------------------------------------------------------------------------- /Orchestrade Financial Systems Software Engineer/README.md: -------------------------------------------------------------------------------- 1 | # Technical Phone Interview 2 | - The phone interview was 45 minutes long. 3 | - I was asked to code this in Google Docs so I could not run my code 4 | 5 | ## 1. Technical Questions 6 | ----- 7 | - What is deadlock 8 | - What can you not do with a class with private constructor 9 | - What is finally block 10 | - How does hashmap work 11 | - What should be a concerns when you are designing the hashmap 12 | - Differnce between deep copy and shallow copy 13 | 14 | 15 | ## 2. Coding and Debugging Round 16 | ----- 17 | 18 | ### 1. Debug Hash function 19 | What is wrong in the below code: 20 | 21 | public override int GetHashCode(List listA, bool isA){ 22 | 23 | return IsA.GetHashCode()*31 + listA.GetHashCode(); 24 | } 25 | 26 | 27 | 28 | ### 2. Is the String Duplicate? 29 | - Write a function to see if there is any duplicate character in the string. 30 | - The string will contain only ascii characters. 31 | - The function should have a time complexity of O(n) and space complexity of O(1). 32 | 33 | 34 | 35 | ### 3. What's Wrong in Parallel Computing 36 | - `ConcurrentDictionary` is a Dictionary which is thread safe. 37 | - `DoCompute` function is costly. 38 | - What is wrong in the below code when multiple threads execute `Compute` function at the same time: 39 | 40 | 41 | ConcurrentDictionary _resultCache = new ConcurrentDictionary(); 42 | 43 | public double Compute(ComputeParams params){ 44 | 45 | double result; 46 | if (_resultCache.TryGetValue(params, out result)) return result; 47 | var result = DoCompute(params); 48 | _resultCache[params] = result; 49 | return result; 50 | } 51 | 52 | double DoCompute(ComputeParams params){ 53 | 54 | // calculate 55 | } 56 | -------------------------------------------------------------------------------- /Orchestrade Financial Systems Software Engineer/isDuplicate.py: -------------------------------------------------------------------------------- 1 | # Time Complexity: O(n) 2 | # Space Complexity: O(1) 3 | 4 | 5 | def is_duplicate(input_string): 6 | if len(input_string)>256: 7 | return True 8 | 9 | flags = [False]*256 10 | for char in input_string: 11 | if not flags[ord[char]]: 12 | flags[ord[char]] 13 | else: 14 | return True 15 | return False 16 | -------------------------------------------------------------------------------- /QuantumBlack Machine Learning Software Engineer 2019/Correlation.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | def Correlation(scores): 5 | physics = [] 6 | maths = [] 7 | chemistry = [] 8 | 9 | for each_scores in scores: 10 | values = each_scores.split("\t") 11 | maths.append(int(values[0])) 12 | physics.append(int(values[1])) 13 | chemistry.append(int(values[2])) 14 | 15 | length = len(physics) 16 | value1 = calculate_correlation(maths, physics, length) 17 | value2 = calculate_correlation(physics, chemistry, length) 18 | value3 = calculate_correlation(chemistry, maths, length) 19 | 20 | # print(value1) 21 | # print(value2) 22 | # print(value3) 23 | return [str(value1), str(value2), str(value3)] 24 | 25 | 26 | # return '{}\{}{}'.format(value1, value2, value3) 27 | 28 | def calculate_correlation(list1, list2, length): 29 | # print("into calculate_correlation", list2, list1, length) 30 | multiply_list = [each[0] * each[1] for each in zip(list1, list2)] 31 | 32 | num_termA = sum(multiply_list) * length 33 | num_termB = sum(list1) * sum(list2) 34 | numerator = num_termA - num_termB 35 | 36 | # print("tA: {}, tB: {}, n: {}".format(num_termA, num_termB, numerator)) 37 | 38 | denom_calculator = lambda lis, l: math.sqrt((sum(list([pow(each, 2) for each in lis])) * l) - pow(sum(lis), 2)) 39 | 40 | denominator = denom_calculator(list1, length) * denom_calculator(list2, length) 41 | value = round(numerator / denominator, 2) 42 | # print("deno: {}, value: {}".format(denominator, value)) 43 | return value 44 | 45 | 46 | class_scores = ['73\t72\t76', '48\t67\t76', '95\t92\t95', '95\t95\t96', '33\t59\t79', '47\t58\t74', '98\t95\t97', 47 | '91\t94\t97', '95\t84\t90', '93\t83\t90', '70\t70\t78', '85\t79\t91', '33\t67\t76', '47\t73\t90', 48 | '95\t87\t95', '84\t86\t95', '43\t63\t75', '95\t92\t100', '54\t80\t87', '72\t76\t90'] 49 | 50 | res = Correlation(class_scores) 51 | print(res) 52 | -------------------------------------------------------------------------------- /QuantumBlack Machine Learning Software Engineer 2019/Images/Correlation.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/QuantumBlack Machine Learning Software Engineer 2019/Images/Correlation.JPG -------------------------------------------------------------------------------- /QuantumBlack Machine Learning Software Engineer 2019/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | 4 | ## 1. Computing the Correlation 5 | ----- 6 | You are given the scores of **N** students in three different subjects, Maths, Physics, and Chemistry. 7 | All three are graded on a scale of 0 to 100. 8 | Your task is to compute the Pearson product moment correlation coefficient between the scores of different pairs of subject. 9 | This data is based on the records of the CBSE K-12 Exam, a national school leaving exam in India, for year 2013. 10 | 11 | Pearson product-moment correlation coefficient: 12 | This is a measure of linear correlation between data series: 13 | 14 | [image1]: ./Images/Correlation.JPG "Correlation" 15 | ![Correlation][image1] 16 | 17 | 18 | Input Format: 19 | The first row contains an integer **N**. 20 | This is followed by **N** rows containing three space-separated integers **M, P, C** corresponding to a candidate's scores in Maths, Physics, Chemistry. 21 | Each row contains to the scores obtained in these three subjects by one students. 22 | 23 | Input Constraints: 24 | - 1 <= N <= 500000 25 | - 0 <= M, P, C <= 100 26 | 27 | Output Format: 28 | The output should contain three lines, with correlation coefficients computed and rounded **off to exactly 2 decimal places.** 29 | The first line should contain the correlation coefficient between Maths and Physics scores. 30 | The second line should contain the correlation coefficient between Physics and Chemistry scores. 31 | The third line should contain the correlation coefficient between Chemistry and Maths scores. 32 | 33 | 34 | 35 | 36 | ## 2. Distinct Pairs 37 | ----- 38 | In this challenge, you will be given an array of integers and a target value. 39 | Determining the number of distinct pairs of elements in the array that sum to the target value. 40 | Two pairs (a, b) and (c, d) are considered to be distinct if and only if the values in sorted order do not match, i.e., (1, 9) and (9, 1) are indistinct but (1, 9 ) and (9, 2) are distinct. 41 | 42 | For instance given the array [1, 2, 3, 6, 7, 8, 9, 1] and a target value of 10, the seven pairs (1, 9), (2, 8), (3, 7), (8, 2), (9,1), and (1, 9) all sum to 10 and only three distinct pair: (1, 9), (2, 8), and (3, 7). 43 | 44 | Function Description: 45 | Complete the function numberOfPairs. The function must return an integer, the total number of distinct pairs of elements in the array that sum to the target value. 46 | 47 | numberOfPairs has following parameters: 48 | a[a[0], ..., an-1]]: an array of integers to select the pairs from 49 | k: target integer value to sum to 50 | 51 | Constraints: 52 | - 1 <= n <= 500000 53 | - 0 <= a[i] <= 1000000000 54 | - 0 <= k <= 500000 55 | 56 | Sample Input 0: 57 | 6 58 | 1 59 | 3 60 | 46 61 | 1 62 | 3 63 | 9 64 | 47 65 | 66 | Sample Output 0: 67 | 1 68 | 69 | Explanation 0: 70 | a = [1, 3, 46, 1, 3, 9], k = 47 71 | There are 4 pairs of unique elements where a[i]+a[j] = k 72 | 1. (a[0] = 1, a[2] = 46) 73 | 2. (a[2] = 46, a[0] = 1) 74 | 3. (a[2] = 46, a[3] = 1) 75 | 4. (a[3] = 1, a[2] = 46) 76 | 77 | ## 3. Simple queries 78 | ----- 79 | 80 | Given two array if positive integer, for each element in the second array, find the total number of elements in the first array which are less than or equal to that element. 81 | Store the values determined in an array. 82 | For example, if the first array is `[1, 2, 3]` and the second array is `[2, 4]`, then the there are 2 elements in the first array less than or equal to 2. 83 | There are 3 elements in the first array which are less than or equal to 4. 84 | We can store these answers in an array, answer = [2, 3]. 85 | 86 | Function Description: 87 | Complete the function `counts`. 88 | The function must return an array of m positive integers, one for each maxes[i] representing the total number of elements nums[j] satisfying nums[j]<=maxes[i], where 0 <= j < n and 0 <= i < m, in given order 89 | 90 | counts has the following parameters: 91 | num[nums[0], ,..., nums[n-1]]: first array of positive integers 92 | maxes[maxes[0], ,..., maxes[n-1]]: second array of positive integers 93 | 94 | 95 | Constraints: 96 | - 2 <= n, m <= 100000 97 | - 1 <= nums[j] <= 1000000000, where 0 <= j < n 98 | - 1 <= maxes[i] <= 1000000000, where 0 <= i < m. 99 | 100 | Sample Input 0: 101 | 4 102 | 1 103 | 4 104 | 2 105 | 4 106 | 2 107 | 3 108 | 5 109 | 110 | Sample Output 0: 111 | 2 112 | 4 113 | 114 | Explanation 0: 115 | We are given n = 4, nums = [1, 4, 2, 4], m = 2, and maxes = [3, 5]. 116 | 1. For maxes[0] = 3, we have 2 elements in nums (nums[0] = 1, and nums[2] = 2) that are <= maxes[0]. 117 | 2. For maxes[1] = 5, we have 4 elements in nums (nums[0] = 1, nums[1] = 4, nums[2] = 2, and nums[3] = 4) that are <= maxes[1]. 118 | Thus the function returns the array [2, 4] as the answer. -------------------------------------------------------------------------------- /QuantumBlack Machine Learning Software Engineer 2019/numOfPairs.py: -------------------------------------------------------------------------------- 1 | def numberOfPairs(a, k): 2 | history = {} 3 | result = set() 4 | for num in a: 5 | if num in history: 6 | result.add(tuple(sorted([num, history[num]]))) 7 | else: 8 | history[num] = k - num 9 | 10 | return len(result) 11 | -------------------------------------------------------------------------------- /QuantumBlack Machine Learning Software Engineer 2019/simpleQuery.py: -------------------------------------------------------------------------------- 1 | # Complete the counts function below. 2 | def bin_search(arr, target): 3 | left, ryt = 0, len(arr)-1 4 | while left= 0 and left<=ryt: 5 | mid = (left+ryt)//2 6 | if arr[mid] == target: 7 | return mid+1 8 | elif arr[mid]>target: 9 | ryt = mid-1 10 | else: 11 | left = mid+1 12 | return left 13 | 14 | def counts(nums, maxs): 15 | nums = sorted(nums) 16 | results = [] 17 | for maxi in maxs: 18 | count = bin_search(nums, maxi) 19 | results.append(count) 20 | return results 21 | 22 | 23 | arr = [1, 2, 4, 4, 7] 24 | maxes = [3, 5] 25 | res = counts(arr, maxes) 26 | print("numbers =", arr, "maxes =", maxes, "answer =", res) 27 | 28 | arr = [2, 10, 5, 4, 8] 29 | maxes = [3, 1, 7, 8] 30 | res = counts(arr, maxes) 31 | print("numbers =", arr, "maxes =", maxes, "answer =", res) 32 | 33 | arr = [1, 4, 2, 4] 34 | maxes = [3, 5] 35 | res = counts(arr, maxes) 36 | print("numbers =", arr, "maxes =", maxes, "answer =", res) 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | - This repository is for the ones who want to do well in their coding interviews. 2 | - This repository will help you know what kind of questions to expect and you can also practice the questions in this repository. 3 | - I am creating this repository because initially I faced a lots of rejection because there was no resource like this. 4 | - I want others to do good in their coding interviews, hence I am making this repository public. 5 | - If you think that this repository is helpful then don't forget to star :star: this repository, so that others can discover this repository. 6 | - Do Read my article on Medium [How to do well in a coding interview](https://medium.com/@jayshah_84248/how-to-do-well-in-a-coding-interview-2bcd67e93cb5) 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 |
Company Interview Table Sorted by Month-Year
CompanyPositionAppliedTest
Amazon SDE - 1 FinTech team Feb 2019 Amazon
INVIDI Software Developer 2019 Feb 2019 Online Assessment
Design Elevator VISA Senior Software Engineer Part of VISA onsite
Amazon SDE 2019 Intern Jan 2019 Amcat Online Assessment
Apple Jr. Python Developer Jan 2019 HireVue Online Assessment
Twilio University Internship Jan 2019 Hackerrank Online Assessment
Wayfair Labs Software Engineer 2019 Jan 2019 Round-1 Online Assessment,
Round-2 HR Phone Interview
Amazon SDE-1-FBA team Dec 2018 Amcat Online Assessment
Akuna Capital Jr. Python Developer Nov 2018 Hackerrank Online Assessment
Guidewire Backend Software Engineer Entry Level Nov 2018 Round-1 Technical Phone Interview,
Round-2 Online Assessment
Orchestrade Financial Systems Software Engineer Nov 2018 Technical Phone Interview
BNY Mellon Backend Software Developer Oct 2018 Hackerrank Online Assessment
Twilio Part 1 Software Engineer New Grad 2019 Oct 2018 Hackerrank Online Assessment
Twilio Part 2 Software Engineer New Grad 2019 Oct 2018 Hackerrank Online Assessment
TwoSigma Software Engineer Investment Oct 2018 Round-1 Hackerrank Online Assessment,
Round-2 HR,
Round-3 Technical Phone Interview
VISA 2019 Senior Software Engineer Oct 2018 Round-1 Hackerrank Online Assessment,
Round-2 Technical Phone Interview,
Round-3 Onsite
Quantum Black Machine Learning Software Engineer Oct 2018 Hackerrank Online Assessment
Workday Software Development Engineer Oct 2018 Hackerrank Online Assessment
Workday Software Java Platform Developer Oct 2018 Hackerrank Online Assessment
ClassPass Software Engineer - New Grad 2019 Oct 2018 Codility Online Assessment
LinkedIn Software Engineer Entry Level 2019 Oct 2018 Hackerrank Online Assessment
Coursera Part 1 Software Engineer Entry Level 2019 Oct 2018 Hackerrank Online Assessment
Coursera Part 2 Software Engineer Entry Level 2019 Oct 2018 Hackerrank Online Assessment
SAP Silicon Valley Next Talent Program 2019 Sept 2018 SAP Online Assessment
Harman International Software Engineer 2019 Sept 2018 Round-2: WebEx Interview
Jet.com (Walmart Company) Software Engineer - Big Data Aug 2018 Round-1: Coding Phone Interview
BitGo Software Test Engineer July 2018 Round-1 Hackerrank Online Assessment,
Round-2 HR Phone Interview,
Round-3 Technical Phone Interview
Google Software Engineer New Grad 2018 June 2018 Round-1 Technical Phone Interview,
Final-round: On-site
228 | -------------------------------------------------------------------------------- /SAP Silicon Valley Next Talent Program 2019/README.md: -------------------------------------------------------------------------------- 1 | ## 1. Search Index or Insert Position 2 | --------- 3 | Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. 4 | You may assume no duplicates in the array. 5 | 6 | ## 2. Move Zeroes 7 | ----- 8 | Given an array `arr`, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. 9 | 10 | Example: 11 | 12 | Input: [0,1,0,3,12] 13 | Output: [1,3,12,0,0] 14 | 15 | ## 3. Maximum Depth of N-ary Tree 16 | ----- 17 | 18 | Given a n-arry tree, find its maximum depth. 19 | The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 20 | -------------------------------------------------------------------------------- /SAP Silicon Valley Next Talent Program 2019/findDepth.py: -------------------------------------------------------------------------------- 1 | def maxDepth(root): 2 | if not root: 3 | return 0 4 | max_depth = [1] 5 | dfs(root, 1, max_depth) 6 | return max_depth[0] 7 | 8 | 9 | def dfs(root, depth, max_depth): 10 | if max_depth[0] < depth: 11 | max_depth[0] = depth 12 | 13 | if root: 14 | for child in root.children: 15 | dfs(child, depth + 1, max_depth) 16 | -------------------------------------------------------------------------------- /SAP Silicon Valley Next Talent Program 2019/findIndex.py: -------------------------------------------------------------------------------- 1 | def find_idx(sorted_arr, target): 2 | length = len(sorted_arr) 3 | left = 0 4 | right = length-1 5 | while (left <= right) and (right >= 0) and (left < length): 6 | 7 | middle = (left+right)//2 8 | if sorted_arr[middle] == target: 9 | 10 | return middle 11 | 12 | elif sorted_arr[middle] < target: 13 | left = middle+1 14 | else: 15 | right = middle-1 16 | 17 | return left 18 | -------------------------------------------------------------------------------- /SAP Silicon Valley Next Talent Program 2019/moveZeros.py: -------------------------------------------------------------------------------- 1 | def move_zeros(arr): 2 | i = j = 0 3 | while i < len(arr): 4 | if arr[i] > 0: 5 | arr[j] = arr[i] 6 | j += 1 7 | i += 1 8 | 9 | while j < len(arr): 10 | arr[j] = 0 11 | j += 1 12 | 13 | return arr 14 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-1/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | - I was given 45 minutes to solve the two questions. 4 | 5 | 6 | ## 1. Reformatting Dates 7 | ----- 8 | Given a date string in the format Day Month Year where: 9 | 10 | Day is in set {"1st", "2nd", "3rd", "4th", "5th", "6th", .... , "31st"}. 11 | 12 | Month is in set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 13 | "Jul", "Aug", "Sep" , "Oct" , "Nov", "Dec"}. 14 | 15 | Year is in the inclusive range [1900, 2100] 16 | 17 | For Example: 18 | - "1st Mar 1984" -> "1984-03-01" 19 | - "2nd Feb 2013" -> "2013-02-02" 20 | - "4th Apr 1990" -> "1990-04-04" 21 | 22 | 23 | Function Description: 24 | Complete the function `reformateDate` in the editor below. 25 | The function must return an array of converted date strings in the order presented. 26 | 27 | `reformateDate` has the following parameter(s): 28 | - dates[dates[0], ..., dates[n-1]]: an array of date strings in the format Day Month Year 29 | 30 | 31 | Constraints: 32 | - The values of Day, Month, Year are restricted to the value ranges specified above. 33 | - The given dates are guaranteed to be valid so no error handling is necessary. 34 | - 1 <= n <= 10000 35 | 36 | Sample Input 0: 37 | 10 38 | 20th Oct 2052 39 | 6th Jun 1933 40 | 26th May 1960 41 | 20th Sep 1958 42 | 16th Mar 2068 43 | 25th May 1912 44 | 16th Dec 2018 45 | 26th Dec 2061 46 | 4th Nov 2030 47 | 28th Jul 1963 48 | 49 | Sample Output 0: 50 | 2052-10-20 51 | 1933-06-06 52 | 1960-05-26 53 | 1958-09-20 54 | 2068-03-16 55 | 1912-05-25 56 | 2018-12-16 57 | 2061-12-26 58 | 2030-11-04 59 | 1963-07-28 60 | 61 | 62 | 63 | ## 2. Hosts and Total Number of Requests 64 | ----- 65 | In this challenge, write a program to analyze a log file and summarize the results. 66 | Given a text file of an http requests log, list the number of requests from each host. 67 | Output should be directed to a file as described in the Program Description below. 68 | 69 | The format of the log file, a text file with a `.txt` extension, follows. 70 | Each line contains a single log record with the following columns (in order): 71 | 1. The hostname of the host making the request. 72 | 2. This column's value are missing and were replaced by hyphen. 73 | 3. This column's value are missing and were replaced by hyphen. 74 | 4. A timestamp enclosed in square brackets following the format [DD/mm/YYY:HH:MM:SS-0400]. 75 | 5. The request, enclosed in quotes(eg, "GET/images/NASA-logosmall.gif HTTP/1.0"). 76 | 6. The HTTP response code. 77 | 7. The total number of bytes sent in the response. 78 | 79 | 80 | Function Description: 81 | Your function must create a unique list of hostnames with their number of requests and output to a file names records_filename where filename is names `records_filename` where `filename` is replaced with input `filename`. 82 | Each `hostname` should be followed by a space then the number of requests and a newline. 83 | Order doesn't matter. 84 | 85 | 86 | 87 | Constraints: 88 | - The log file has a maximum pf 200000 lines of records 89 | 90 | Sample Input 0: 91 | host_access_log_00.txt 92 | 93 | Sample Output 0: 94 | unicomp6.unicompt.net 4 95 | burger.letters.com 3 96 | d104.aa.net 3 97 | 98 | Explanation 0: 99 | The log file hosts_access_log_00.txt contains the following log records; 100 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:06 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 3985 101 | burger.letters.com - - [01/JUL/1995:00:00:11 - 0400] "GET /shuttle/countdown/liftoff.html HTTP/1.0" 304 0 102 | burger.letters.com - - [01/JUL/1995:00:00:12 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 304 0 103 | burger.letters.com - - [01/JUL/1995:00:00:12 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 0 104 | d104.aa.net - - [01/JUL/1995:00:00:13 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 3985 105 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:14 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 40310 106 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:14 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 786 107 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:14 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 1204 108 | d104.aa.net - - [01/JUL/1995:00:00:15 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 40310 109 | d104.aa.net - - [01/JUL/1995:00:00:15 - 0400] "GET /images/NASA-logosmall.gif HTTP/1.0" 200 786 -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-1/input.txt: -------------------------------------------------------------------------------- 1 | unicomp6.unicompt.net - - 2 | burger.letters.com - - 3 | burger.letters.com - - 4 | burger.letters.com - - 5 | d104.aa.net - - 6 | unicomp6.unicompt.net - - 7 | unicomp6.unicompt.net - - 8 | unicomp6.unicompt.net - - 9 | d104.aa.net - - 10 | d104.aa.net - - 11 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-1/records_input.txt: -------------------------------------------------------------------------------- 1 | unicomp6.unicompt.net 4 2 | burger.letters.com 3 3 | d104.aa.net 3 4 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-1/reformateDate.py: -------------------------------------------------------------------------------- 1 | def reformateDate(dates): 2 | days2num = {"1st": "01", "2nd": "02", "3rd": "03", "4th": "04", "5th": "05", "6th": "06", 3 | "7th": "07", "8th": "08", "9th": "09", "10th": "10", "11th": "11", "12th": "12", 4 | "13th": "13", "14th": "14", "15th": "15", "16th": "16", "17th": "17", "18th": "18", 5 | "19th": "19", "20th": "20", "21st": "21", "22nd": "22", "23rd": "23", "24th": "24", 6 | "25th": "25", "26th": "26", "27th": "27", "28th": "28", "29th": "29", "30th": "30", "31st": "31"} 7 | 8 | month2num = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06", 9 | "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12"} 10 | 11 | results = [] 12 | for date in dates: 13 | day, month, year = date.split() 14 | res = year+"-"+month2num[month]+"-"+days2num[day] 15 | results.append(res) 16 | return results 17 | 18 | 19 | date_list = ["1st Mar 1984", "2nd Feb 2013", "4th Apr 1990"] 20 | correct_format = reformateDate(date_list) 21 | print(correct_format) 22 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-1/totalRequests.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | def read_file(filename): 5 | host2req = defaultdict(int) 6 | with open(filename) as file: 7 | for line in file: 8 | line_list = line.split() 9 | host2req[line_list[0]] += 1 10 | 11 | file = open("records_"+filename, "w") 12 | for host in host2req: 13 | file.write(host+" "+str(host2req[host])+"\n") 14 | file.close() 15 | 16 | 17 | file_name = input() 18 | read_file(file_name) -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-2/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | - I was given 45 minutes to solve the two questions. 4 | 5 | 6 | ## 1. Hosts and Total Number of Requests 7 | ----- 8 | In this challenge, write a program to analyze a log file and summarize the results. 9 | Given a text file of an http requests log, list the number of requests from each host. 10 | Output should be directed to a file as described in the Program Description below. 11 | 12 | The format of the log file, a text file with a `.txt` extension, follows. 13 | Each line contains a single log record with the following columns (in order): 14 | 1. The hostname of the host making the request. 15 | 2. This column's value are missing and were replaced by hyphen. 16 | 3. This column's value are missing and were replaced by hyphen. 17 | 4. A timestamp enclosed in square brackets following the format [DD/mm/YYY:HH:MM:SS-0400]. 18 | 5. The request, enclosed in quotes(eg, "GET/images/NASA-logosmall.gif HTTP/1.0"). 19 | 6. The HTTP response code. 20 | 7. The total number of bytes sent in the response. 21 | 22 | 23 | Function Description: 24 | Your function must create a unique list of hostnames with their number of requests and output to a file names records_filename where filename is names `records_filename` where `filename` is replaced with input `filename`. 25 | Each `hostname` should be followed by a space then the number of requests and a newline. 26 | Order doesn't matter. 27 | 28 | 29 | 30 | Constraints: 31 | - The log file has a maximum pf 200000 lines of records 32 | 33 | Sample Input 0: 34 | host_access_log_00.txt 35 | 36 | Sample Output 0: 37 | unicomp6.unicompt.net 4 38 | burger.letters.com 3 39 | d104.aa.net 3 40 | 41 | Explanation 0: 42 | The log file hosts_access_log_00.txt contains the following log records; 43 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:06 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 3985 44 | burger.letters.com - - [01/JUL/1995:00:00:11 - 0400] "GET /shuttle/countdown/liftoff.html HTTP/1.0" 304 0 45 | burger.letters.com - - [01/JUL/1995:00:00:12 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 304 0 46 | burger.letters.com - - [01/JUL/1995:00:00:12 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 0 47 | d104.aa.net - - [01/JUL/1995:00:00:13 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 3985 48 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:14 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 40310 49 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:14 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 786 50 | unicomp6.unicompt.net - - [01/JUL/1995:00:00:14 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 1204 51 | d104.aa.net - - [01/JUL/1995:00:00:15 - 0400] "GET /shuttle/countdown/ HTTP/1.0" 200 40310 52 | d104.aa.net - - [01/JUL/1995:00:00:15 - 0400] "GET /images/NASA-logosmall.gif HTTP/1.0" 200 786 53 | 54 | 55 | ## 2. Missing Words 56 | ----- 57 | Given two strings, one is a subsequence if all of the elements of the first string occur in the same order within the second string. 58 | They do not have to be contiguous in the second string, but order must be maintained. 59 | For example, given the string "I like cheese", the words "I" and "cheese" are one possible subsequence of that string. 60 | 61 | In this challenge, you will be given two strings, `s` and `t`, where `t` is a subsequence of `s`, report the words of `s`, missing in `t`, in order they are missing. 62 | Revisiting the earlier example, if `s = I like cheese` and `t = like`, then like is the longest subsequence, and `[I, cheese]` is the list of missing words in order. 63 | 64 | 65 | Function Description: 66 | Complete the function `missingWords` in the editor below. 67 | It must return an array of strings containing any words in `s` that are missing from `t` in the order they occur within `s`. 68 | 69 | `missingWords` has the following parameter(s): 70 | s: a sentence of space separated words 71 | t: a sentence of space separated words 72 | 73 | Constraints: 74 | - Strings `s` and `t` consists of English alphabetic letters and spaces only. 75 | - 1 <= |t| < |s| 10^6 76 | - 1 <= length of any word in `s` or `t` <= 15 77 | - It is guaranteed that string `t` is a subsequence of string `s`. 78 | 79 | Input Format: 80 | Input from stdin will be processes as follows and passed to the function 81 | The first line contains a string `s`. 82 | The second line contains a string `t`. 83 | 84 | Sample Input 0: 85 | I am using HackerRank to improve programming 86 | am HackerRank to improve 87 | 88 | Sample Output 0: 89 | I 90 | using 91 | programming 92 | 93 | Explanation 0: 94 | The missing words are: 95 | 1. I 96 | 2. using 97 | 3. programming 98 | 99 | We add these words in order to the array ["I", "using", "programming"], then return this array as our answer. 100 | 101 | Sample Input 1: 102 | I love programming 103 | programming 104 | 105 | Sample Output 1: 106 | I 107 | love 108 | 109 | Explanation 1: 110 | The missing words are: 111 | 1. I 112 | 2. love 113 | 114 | We add these words in order to the array ["I", "love"], then return this array as our answer. 115 | 116 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-2/input.txt: -------------------------------------------------------------------------------- 1 | unicomp6.unicompt.net - - 2 | burger.letters.com - - 3 | burger.letters.com - - 4 | burger.letters.com - - 5 | d104.aa.net - - 6 | unicomp6.unicompt.net - - 7 | unicomp6.unicompt.net - - 8 | unicomp6.unicompt.net - - 9 | d104.aa.net - - 10 | d104.aa.net - - 11 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-2/missingWords.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'missingWords' function below. 3 | # 4 | # The function is expected to return a STRING_ARRAY. 5 | # The function accepts following parameters: 6 | # 1. STRING s 7 | # 2. STRING t 8 | # 9 | 10 | 11 | def missingWords(s, t): 12 | # Write your code here 13 | s_list = s.split() 14 | t_list = t.split() 15 | missing = [] 16 | i = j = 0 17 | while i < len(s_list) and j < len(t_list): 18 | if s_list[i] == t_list[j]: 19 | i += 1 20 | j += 1 21 | else: 22 | missing.append(s_list[i]) 23 | i += 1 24 | 25 | for k in range(i, len(s_list)): 26 | missing.append(s_list[k]) 27 | return missing 28 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-2/records_input.txt: -------------------------------------------------------------------------------- 1 | unicomp6.unicompt.net 4 2 | burger.letters.com 3 3 | d104.aa.net 3 4 | -------------------------------------------------------------------------------- /Twilio Software Engineer - New Grad-Part-2/totalRequests.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | def read_file(filename): 5 | host2req = defaultdict(int) 6 | with open(filename) as file: 7 | for line in file: 8 | line_list = line.split() 9 | host2req[line_list[0]] += 1 10 | 11 | file = open("records_"+filename, "w") 12 | for host in host2req: 13 | file.write(host+" "+str(host2req[host])+"\n") 14 | file.close() 15 | 16 | 17 | file_name = input() 18 | read_file(file_name) 19 | -------------------------------------------------------------------------------- /Twilio University Internship 2019/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | - I was given 60 minutes to solve the two questions. 4 | 5 | 6 | ## 1. Distinct Pairs 7 | ----- 8 | In this challenge, you wi;ll be given an array of integers and a target value. 9 | Determine the number of distinct pairs of elements in the array that sum up to the target value. 10 | Two pairs (a, b) and (c, d) are considered to be distinct if and only if the values in sorted order do not match i.e. (1, 9) and (9, 1) are indistinct but (1, 9) and (9, 2) are distinct. 11 | 12 | For Example, given the array `[1, 2, 3, 6, 7, 8, 9, 1]` and a target value of 10, the seven pairs (1, 9), (2, 8), (3, 7), (8, 2), (9, 1), (9, 1) and (1, 9) all sum to 10 and there are only three distinct pairs: (1, 9), (2, 8), and (3, 7). 13 | 14 | 15 | Function Description: 16 | Complete the function `numberOfPairs` in the editor below. 17 | The function must return an integer, the total number of distinct pairs of elements in the array that sum to the target value. 18 | 19 | `numberOfPairs` has the following parameter(s): 20 | - a[a[0], ..., a[n-1]]: an array of integers to select the pairs from. 21 | 22 | 23 | Constraints: 24 | - 1 <= n <= 5 x 10^5 25 | - 0 <= a[i] <= 10^9 26 | - 0 <= k <= 5 x 10^9 27 | 28 | Input Format for Custom Testing 29 | 30 | - The first line contains an integer n, the size of the array a. 31 | - The next n lines each contain an element a[i] where 0 <= i < n. 32 | - The next line contains an integer k, the target value. 33 | 34 | 35 | Input 36 | Sample Input 0: 37 | 6 38 | 1 39 | 3 40 | 46 41 | 1 42 | 3 43 | 9 44 | 47 45 | 46 | Sample Output 0: 47 | 1 48 | 49 | Explanation 0: 50 | a = [1, 3, 46, 1, 3, 9] 51 | There are 4 pairs of unique elements where a[i]+a[j] = k: 52 | 53 | 1. (a[0] = 1, a[2] = 46) 54 | 2. (a[2] = 46, a[0] = 1) 55 | 3. (a[2] = 46, a[3] = 1) 56 | 4. (a[3] = 1, a[2] = 46) 57 | In the list above, all four pairs contain the same values. 58 | We only have 1 distinct pair (1, 46). 59 | 60 | 61 | ## 2. Stock Analysis 62 | ----- 63 | In data analysis, the eliminate algorithm determines the single final value to use for each data parameter. 64 | The eliminate algorithm works in the following way: 65 | - Data is acquired from multiple sources in order from least to most preferred, i.e. If a parameter `Pi` is present in both source 1 and source 2, the parameter from the higher priority source, source 2, is used in the final parameter list, and any value from an earlier source is superseded. 66 | - As new parameters arrive, they are added to the list. 67 | - If a parameter `Pi` is present only in one of the sources, it is directly added to the final parameter list. 68 | Hence, 69 | - The result of performing the above operations until all the parameters from source 1 and source 2 are exhausted is the result of Eliminate-algorithm(source 1, source 2). 70 | - Each time a new value for a parameter is encountered from a higher preferred site, the old data is superseded. 71 | - Assuming three sources S1, S2, and S3. 72 | - Eliminate-algorithm(S1, S2, S3) = Eliminate-algorithm(Eliminate-algorithm(S1, S2), S3) 73 | 74 | Given a list of sources S1, S2, ..., Sn, find the final parameter list given by Eliminate-algorithm(S1, S2, .., Sn). Maintain your result in the order a key was first encountered. 75 | 76 | For example, a rating parameter of buy, sell or hold from three sources in increasing order of preference: [buy, sell, hold], where buy is from S1, immediately superseded by sell S2, immediately superseded by hold S3. 77 | The final rating is the only one that hasn't been superseded, so you use "hold" as the final rating. 78 | 79 | 80 | Function Description: 81 | Complete the function `computeParameterValue` in the editor below. 82 | The function must return an array of strings that denotes the final parameter list values in the order their keys were first encountered. 83 | 84 | `computeParameterValue` has following parameter(s): 85 | sources: A 2-dimensional array of key:value pairs, each row is one source's data, sources presented from lowest to highest preference. 86 | 87 | Constraints: 88 | - 1 <= n < 100 89 | - 1 <= p < 1000 90 | 91 | 92 | Input Format for Custom Testing 93 | 94 | - The first line contains a positive integer n, the number of sources. 95 | - The next line contains a positive integer p, denoting the number of parameters of each source. 96 | - Each of the next n lines contains an array of p space-separated strings of formate key:value, denoting the key and value of source[i] parameters. 97 | 98 | 99 | Input 100 | 101 | Sample Input 0: 102 | 2 103 | 3 104 | P1:a P3:b P5:x 105 | P1:b P2:q P5:x 106 | 107 | Sample Output 0: 108 | b 109 | b 110 | x 111 | q 112 | 113 | Explanation 0: 114 | Final parameter list: 115 | - P1 b (Source 2) 116 | - P3 b (Source 1) 117 | - P5 x (Source 2) 118 | - P2 q (Source 2) 119 | 120 | ## 3. K-Subsequences 121 | ----- 122 | 123 | We define a k-subsequence of an array as follows: 124 | - It is a subsequence of contiguous elements in the array, i.e. a subarray. 125 | - The sum of the subsequence's elements, s, is evenlt divisible by k (i.i: s % k = 0). 126 | 127 | Given an array of integers, determine the number of k-subsequences it contains. 128 | For example k = 5 and the array nums = [5, 10, 11, 9, 5]. 129 | The 10 k-subsequences are: {5}, {5, 10}, {5, 10, 11, 9}, {5, 10, 11, 9, 5}, {10}, {10, 11, 9}, {10, 11, 9, 5}, {11, 9}, {11, 9, 5}, {5}. 130 | 131 | 132 | Function Description: 133 | Complete the function `kSub` in the editor below. 134 | The function must return an long integer that represents the number of k-subsequences. 135 | 136 | `kSub` has following parameter(s): 137 | - k: an integer that the sum of the subsequence must be divisible by 138 | - nums[nums[0], ..., nums[n-1]]: an array of integers 139 | 140 | Constraints: 141 | - 1 <= n <= 3 x 10^5 142 | - 1 <= k <= 100 143 | - 1 <= nums[i] <= 10^4 144 | 145 | 146 | Input Format for Custom Testing 147 | 148 | - The first line contains an integer k, the number the sum of the subsequence must be divisible by. 149 | - The next line contains an integer n, that denotes the number of elements in nums. 150 | - Each line `i` of the `n` subsequent lines (where 0 <= i < n) contains an integer that describes nums[i]. 151 | 152 | 153 | Input 154 | 155 | Sample Input 0: 156 | 3 157 | 5 158 | 1 159 | 2 160 | 3 161 | 4 162 | 1 163 | 164 | Sample Output 0: 165 | 4 166 | 167 | Explanation 0: 168 | The 4 contiguous subsequences of nums having sums that are evenly divisible be k = 3 are: 169 | {3}, {1, 2}, {1, 2, 3}, {2, 3, 4} -------------------------------------------------------------------------------- /Twilio University Internship 2019/distinctPairs.py: -------------------------------------------------------------------------------- 1 | def numberOfPairs(nums, target): 2 | if len(nums) <= 1: 3 | return 0 4 | 5 | distinct_pairs = set([]) 6 | nums = sorted(nums) 7 | 8 | for i, num in enumerate(nums): 9 | search_res = binary_search(nums, i, len(nums) - 1, target - nums[i]) 10 | if search_res != -1: 11 | distinct_pairs.add(tuple(sorted([num, search_res]))) 12 | return len(distinct_pairs) 13 | 14 | 15 | def binary_search(arr, l, r, x): 16 | idx = l 17 | while r >= l: 18 | mid = (l + r) // 2 19 | 20 | if arr[mid] == x: 21 | if mid != idx: 22 | return arr[mid] 23 | else: 24 | if arr[mid - 1] == x or arr[mid + 1] == x: 25 | return arr[mid] 26 | else: 27 | return -1 28 | elif arr[mid] > x: 29 | r = mid - 1 30 | else: 31 | l = mid + 1 32 | 33 | return -1 34 | -------------------------------------------------------------------------------- /Twilio University Internship 2019/kSubseq.py: -------------------------------------------------------------------------------- 1 | def kSub(k, arr): 2 | n = len(arr) 3 | mod = [0 for _ in range(k + 1)] 4 | result = cumSum = 0 5 | 6 | for i in range(n): 7 | cumSum = cumSum + arr[i] 8 | mod[((cumSum % k) + k) % k] = mod[((cumSum % k) + k) % k] + 1 9 | 10 | for i in range(k): 11 | if mod[i] > 1: 12 | result = result + (mod[i] * (mod[i] - 1)) // 2 13 | 14 | return result + mod[0] 15 | -------------------------------------------------------------------------------- /Twilio University Internship 2019/stockAnalysis.py: -------------------------------------------------------------------------------- 1 | def computeParameterValue(sources): 2 | mapping = {} 3 | for idx, source in enumerate(sources): 4 | for kv in source: 5 | k, v = kv.split(":") 6 | mapping[k] = v 7 | 8 | results = [] 9 | for key in mapping: 10 | results.append(mapping[key]) 11 | return results 12 | -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/README.md: -------------------------------------------------------------------------------- 1 | ## Interview Description 2 | ---- 3 | - At this point of time I have cleared three interview rounds of Two Sigma. 4 | 5 | ## Round 1 (Hackerrank Online Assessment) 6 | --- 7 | - 1st round was hackerank round. 8 | - I got 2 questions which I had to solve in 90 minutes. 9 | 10 | 11 | ## Round 2 (HR Phone Interview) 12 | --- 13 | - 2nd round was HR telephonic round. 14 | - HR asked me about my background. 15 | 16 | ## Round 3 (Technical Phone Interview) 17 | --- 18 | - 3rd round is a technical phone interview. 19 | - The interviewer asked me about Computer Science questions in the 1st 30 minutes. 20 | - In the next 30 minutes I had to solve a coding question on Hackerrank's CodePair. 21 | 22 | 23 | -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/Round 1 - Hackerrank Online Assessment/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | 4 | ## 1. Friend Circles 5 | ----- 6 | 7 | There are N students in a class. Some of them are friends, while some are not. 8 | Their friendship is transitive in nature, i.e., if **A** is friend of **B** and **B** is friend of **C**, then **A** is also friend of **C**. 9 | A friend circle is a group of students who are directly or indirectly friends. 10 | 11 | You have to complete a function `int friendCircles(char[][] friends)` which return the number of friend circles in the class. Its argument, friends, is a `NxN` matrix which consists of characters "Y" or "N". 12 | If `friends[i][j] == "Y" then `i-th` and `j-th` students are friends with each other, otherwise not. You have to return the total number of friend circles in the class. 13 | 14 | 15 | 16 | Constraints 17 | - 1 <= N <= 300. 18 | - Each element of matrix friends will be "Y" or "N". 19 | - Number of rows and columns will be equal in `friends`. 20 | - friends[i][j] = "Y", where 0 <= i < N. 21 | - friends[i][j] = friends[j][i], where 0 <= i < j < N. 22 | 23 | Sample Input 0: 24 | 4 25 | YYNN 26 | YYYN 27 | NYYN 28 | NNNY 29 | Sample Output 0: 30 | 2 31 | 32 | Explanation 0: 33 | There are two pairs of friends [0, 1] and [1, 2]. So [0, 2] is also a pair of friends by transitivity. 34 | So first friend circle contains (0, 1, 2) and second friend circle contains only student 3 35 | 36 | Sample Input 1: 37 | 5 38 | YNNNN 39 | NYNNN 40 | NNYNN 41 | NNNYN 42 | NNNNY 43 | Sample output 1: 44 | 5 45 | 46 | 47 | 48 | ## 2. String Chains 49 | ---- 50 | 51 | Given an array of words representing your dictionary, you test words to see if it can be made into another word in dictionary. 52 | This will be done by removing characters one at a time. 53 | Each word represents its own first element of its string chain, so start with a string chain length of 1. 54 | Each time you remove a character, increment your string chain by 1. In order to remove a character the resulting word must be in your original dictionary. 55 | Your goal is to determine the longest string chain available for a given dictionary. 56 | 57 | 58 | 59 | for example, given a dictionary [a, and, ab, bear] the word **and** could be reduced to **an** and the word **an** to **a**. 60 | The single character **a** can not be reduced to any further as the null string is not in the dictionary. 61 | This  would be the longest string chain, having a length 3. The word **bear** can not be reduced at all. 62 | 63 | 64 | 65 | Constraints: 66 | 67 | - 1 <= n <= 50000 68 | - 1 <= words[i] <= 60, where 0 <= i <= n 69 | - Each words[i] is composed of lowercase letter in ascii[a-z] 70 | 71 | 72 | Input: ["a", "b", "ba", "bca", "bda", "bdca"] 73 | 74 | Output: 4 75 | 76 | Constraints 77 | - 1 <= Length of game <= 100000 78 | - s[i] contains either "1" or "0" 79 | 80 | Sample Input 0: 81 | 6 82 | a 83 | b 84 | ba 85 | bca 86 | bda 87 | bdca 88 | 89 | Sample Output 0: 90 | 4 91 | 92 | Explanation 0: 93 | 94 | words = ["a", "b", "ba", "bca", "bda", "bdca"] 95 | the word "bdca" can create four different string chains of length: 4 96 | ("bdca" -> "bda" -> "ba" -> "a", "bdca" -> "bda" -> "ba" -> "b", "bdca" -> "bca" -> "ba" -> "a", "bdca" -> "bca" -> "ba" -> "b") 97 | This means our current longest string chain is 4 98 | -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/Round 1 - Hackerrank Online Assessment/friendCircle.py: -------------------------------------------------------------------------------- 1 | # Complete the friendCircles function below. 2 | 3 | 4 | def friendCircles(friends): 5 | sets = [] 6 | for i in range(0, len(friends)): 7 | sets.append(i) 8 | 9 | for i in range(1, len(friends)): 10 | for j in range(0, i): 11 | if (friends[i][j]) == "Y": 12 | sets[make_sets(i, sets)] = make_sets(j, sets) 13 | 14 | res = set([]) 15 | for i in range(0, len(friends)): 16 | res.add(make_sets(i, sets)) 17 | return len(res) 18 | 19 | 20 | def make_sets(node, sets): 21 | while sets[node] != node: 22 | sets[node] = sets[sets[node]] 23 | node = sets[node] 24 | return node -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/Round 1 - Hackerrank Online Assessment/longestChain.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'longestChain' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts STRING_ARRAY words as parameter. 6 | # 7 | 8 | from collections import defaultdict 9 | 10 | 11 | def longestChain(words): 12 | # Write your code here 13 | if not words: 14 | return 0 15 | 16 | words = sorted(words, key=len) 17 | longest = 0 18 | mapping = defaultdict(int) 19 | for word in words: 20 | if word in mapping: 21 | continue 22 | mapping[word] = 1 23 | for i in range(0, len(word)): 24 | new_word = word[:i]+word[i+1:] 25 | if (new_word in mapping) and ((mapping[new_word]+1)>(mapping[word])): 26 | mapping[word] = mapping[new_word]+1 27 | longest = max(longest, mapping[word]) 28 | return longest 29 | -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/Round 2 - HR Interview/README.md: -------------------------------------------------------------------------------- 1 | ## Round 2 2 | --- 3 | - 2nd round was HR telephonic round. 4 | - HR asked me about my background. 5 | -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/Round 3 - Technical Phone Interview/README.md: -------------------------------------------------------------------------------- 1 | ## 1. Interview Description 2 | ----- 3 | 4 | This interview was a phone interview. 5 | The phone interview was 1 hour interview. 6 | The first 30 minutes of the interview was about technical questions. 7 | The next 30 minutes of the interview was solving a coding question on Hackerrank's CodePair. 8 | 9 | 10 | ## 1. Technical Questions 11 | ----- 12 | 13 | 1. Tell a project where you faced difficulty. 14 | 2. Difference between processes and threads. 15 | 3. How do processes communicate and how do threads communicate. 16 | 4. What is latency and throughput 17 | 18 | ## 2. Maximum Sum Circular Subarray 19 | ---- 20 | 21 | - Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. 22 | - Here, a circular array means the end of the array connects to the beginning of the array. `(Formally, C[i] = A[i] when 0 <= i < A.length, and C[i+A.length] = C[i] when i >= 0.)` 23 | - Also, a subarray may only include each element of the fixed buffer A at most once. `(Formally, for a subarray C[i], C[i+1], ..., C[j], there does not exist i <= k1, k2 <= j with k1 % A.length = k2 % A.length.)` -------------------------------------------------------------------------------- /TwoSigma Software Engineer Investments 2019/Round 3 - Technical Phone Interview/maximumSumCircularSubArray.py: -------------------------------------------------------------------------------- 1 | # Time Complexity - O(n^2) 2 | # Space Complexity - O(n) 3 | # Better solutions out there with O(n) solution 4 | 5 | 6 | def apply_kadenze(arr): 7 | max_so_far = arr[0] 8 | max_ending = arr[0] 9 | for i in range(1, len(arr)): 10 | max_ending = max(arr[i], max_ending + arr[i]) 11 | max_so_far = max(max_so_far, max_ending) 12 | return max_so_far 13 | 14 | 15 | def find_max_sub_array(arr): 16 | if not arr: 17 | return 0 18 | 19 | if len(arr) == 1: 20 | return arr[0] 21 | 22 | global_max = apply_kadenze(arr) 23 | for i in range(len(arr)): # every element 24 | arr = [arr[-1]] + arr[0:-1] # Operation not needed if its a linked list 25 | cur_max = apply_kadenze(arr) 26 | global_max = max(global_max, cur_max) 27 | 28 | return global_max 29 | 30 | 31 | array = [-1, 2, 4, -1] 32 | result = find_max_sub_array(array) 33 | print("results =", result) 34 | 35 | array = [5, -1, 4, 1] 36 | result = find_max_sub_array(array) 37 | print("results =", result) 38 | 39 | array = [10, -1, 2, 3, 4, 5] 40 | result = find_max_sub_array(array) 41 | print("results =", result) 42 | 43 | array = [] 44 | result = find_max_sub_array(array) 45 | print("results =", result) 46 | 47 | array = [-2] 48 | result = find_max_sub_array(array) 49 | print("results =", result) 50 | 51 | -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/README.md: -------------------------------------------------------------------------------- 1 | ## Interview Description 2 | ---- 3 | - At this point of time I have cleared two interview rounds of VISA, Inc. 4 | 5 | ## Round 1 (Hackerrank Online Assessment) 6 | --- 7 | - 1st round was hackerank round. 8 | - I got 3 coding questions and 3 MCQ questions which I had to solve in 120 minutes. 9 | 10 | 11 | ## Round 2 (Technical Phone Interview) 12 | --- 13 | - 3rd round is a technical phone interview. 14 | - The phone interview is of 45 minutes. 15 | - The interviewer asked me to give a introduction. 16 | - He gave me a question on Hackerrank's CodePair which I had to solve. -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/README.md: -------------------------------------------------------------------------------- 1 | # Got these problems in HACKERRANK challenge 2 | 3 | 4 | - I was given 120 minutes to solve the two questions. 5 | 6 | 7 | ## 1. Maximum Streak 8 | ---- 9 | 10 | A project manager wants to look at employee attendance data. Given that m employees are working on the project, 11 | and the manager has the record of the employees present on n days of the project, help him find the maximum number 12 | of consecutive days on which all employees were present and working on the project. 13 | 14 | As an example there are `m = 3` employees and `n = 5` workdays to analyze. 15 | The attendance data strings, `data = [YYY, YYY, YNN, YYN, YYN]`. 16 | There are only two days at the beginning of the period , where all worker are present. 17 | Using zero indexing for employees, employees 1 and 2 are absent on the third day, and employee 2 is also out on the forth and fifth days. 18 | The maximum streak occurs at the beginning and is 2 days long. 19 | 20 | Function Description 21 | Complete the maxStrak function in the editor below. The function must return an integer denoting the maximum number of consecutive days where all the employees of the project are present. 22 | 23 | maxStreak has the following parameters: 24 | m: an integer denoting the number of employees working on the project. 25 | data: an array of n strings, where the value of each element data[i] is a string where `data[i][j]` denotes the `j-th` employee is present on the `i-th` day. 26 | 27 | 28 | Constraints 29 | - 1 <= m <= 10 30 | - 1 <= n <= 100000 31 | - Each data[i][j] belongs {"Y", "N"} 32 | 33 | Sample Input 0: 34 | 2 35 | 2 36 | YN 37 | NN 38 | Sample Output 0: 39 | 0 40 | 41 | 42 | Sample Input 1: 43 | 3 44 | 1 45 | NYY 46 | Sample output 1: 47 | 0 48 | 49 | Sample Input 2: 50 | 4 51 | 5 52 | YNYY 53 | YYYY 54 | YYNY 55 | NYYN 56 | Sample Output 2: 57 | 2 58 | 59 | ## 2. Binary Jumps 60 | ---- 61 | 62 | In a revised game of hopscotch a child is trying to cross a line of tiles with a binary string painted on it. Consider the line of tiles to be like 1D array, where each tile has either a 1 or a 0, and a consecutive series of tiles makes the whole string. The game starts with the child standing in front of the leftmost character of the string. 63 | - All jumps to reach the end of the string can only be on tiles with 0 or only be in the tiles with 1. 64 | - The game is won if the child can reach at the end of the string, taking jumps with minimum required power. The power of a jump is given by the number of tiles in the path of a jump as indicated in the diagram below. In 10101, the power of the jump from beginning to the first tile is 1 but from the first tile to the third tile is 2, and so on 65 | 66 | Find the minimum power the child's jump should have in order to win the game for different binary strings. 67 | Note: The value on the last tile determines which tiles to jump on. This is because all tiles landed on mush have the same value and the child must land on the last tile to complete the fame. In one jump, the child can jump to the right, any distance from 1 to the value of the power of her jump. 68 | 69 | [image1]: ./images/BinaryJumpsExample.JPG "BinaryJumpsExample" 70 | ![BinaryJumpsExample][image1] 71 | 72 | Constraints 73 | - 1 <= Length of game <= 100000 74 | - s[i] contains either "1" or "0" 75 | 76 | Sample Input 0: 77 | 11111 78 | Sample Output 0: 79 | 1 80 | 81 | 82 | Sample Input 1: 83 | 10101 84 | Sample output 1: 85 | 2 86 | 87 | 88 | ## 3. Flower Bouquets 89 | ---- 90 | Lara owns a flower shop, where she sells only two types of flower bouquets: 91 | - Type 1: the first type of bouquet contains three roses and costs p dollars. 92 | - Type 2: The second type of bouquet contains one cosmos and one rose and costs q dollars. 93 | 94 | Lara grows these flowers in her own garden in a single tow. Consider the row as a one-dimensional array, here each cell either contains a rose or a cosmos. For example array 001101011, here 0 indicates rose and 1 indicates cosmos. 95 | 96 | [image2]: ./images/FlowerBouquets.JPG "FlowerBouquets" 97 | ![FlowerBouquets][image2] 98 | 99 | 100 | Lara follows an important rule when she makes the bouquets: she makes each bouquet with only consecutive flowers from the array. 101 | For example in a bouquet, the flower from consecutive (i, i+1, and i+2) in the array can be present, but not from non-consecutive indices (i and i+2) in the array above, Lara can not make any bouquets of type 1 but she can make 3 bouquets of type 2 102 | 103 | Now she wonder what is the maximum profit she can make if she makes these bouquets optimally. You are given a binary string representing her garden row. calculate the maximum profit Lara can make. Remember that it is not necessary to use every flower 104 | 105 | Function Description: 106 | 107 | Complete the flowerBouquets function in the editor below. The function must return an integer that denotes the maximum profit Lara can make if she makes her bouquet optimally. 108 | 109 | flowerBouqets has three parameters: 110 | - p: integer denoting the cost of a bouquet of type 1. 111 | - q: integer denoting the cost of a bouquet of type 2. 112 | - s: string denoting the garden pattern, where zero indicated rose and on indicates cosmos 113 | 114 | Constraints: 115 | 116 | - 1 <= p,q <= 1000 117 | - 1 <= |s| <= 100000 118 | 119 | 120 | Sample Input 0: 121 | 2 122 | 123 | 3 124 | 0001000 125 | Sample Output 0: 126 | 5 127 | 128 | Explanation 0 129 | Lara can make two bouquets of three roses by the corresponding indexes: [0, 1, 2] and [4, 5, 6] and can earn 2+2 = 4 profit. 130 | **OR** 131 | Lara can make one bouquet of three roses by the corresponding indexes: [0, 1, 2] and one bouquet of one rose and one cosmos by corresponding indexes (3, 4) and can earn 2+3 = 5 profit. 132 | 5 i greater than 4 so print 5 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/flowerBouquets.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'flowerBouquets' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts following parameters: 6 | # 1. INTEGER p 7 | # 2. INTEGER q 8 | # 3. STRING s 9 | # 10 | 11 | 12 | def findMaxProfit(jobs): 13 | tabulation = [] 14 | for i in range(len(jobs)): 15 | tabulation.append(jobs[i][2]) 16 | for i in range(len(jobs)): 17 | for j in range(i + 1, len(jobs)): 18 | if jobs[i][1] < jobs[j][0]: 19 | tabulation[j] = max(tabulation[j], jobs[j][2] + tabulation[i]) 20 | return tabulation[-1] 21 | 22 | 23 | def flowerBouquets(p, q, s): 24 | if len(s) <= 1: 25 | return 0 26 | jobs = [] 27 | type1 = "000" 28 | 29 | for i in range(len(s)): 30 | if s[i:i + 3] == type1: 31 | jobs.append([i, i + 2, p]) 32 | else: 33 | cur = s[i: i + 2] 34 | if cur == "01" or cur == "10": 35 | jobs.append([i, i + 1, q]) 36 | if not jobs: 37 | return 0 38 | return findMaxProfit(jobs) 39 | -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/images/BinaryJumpsExample.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/images/BinaryJumpsExample.JPG -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/images/FlowerBouquets.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/images/FlowerBouquets.JPG -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/maxStreak.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'maxStreak' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts following parameters: 6 | # 1. INTEGER m 7 | # 2. STRING_ARRAY data 8 | # 9 | 10 | 11 | def maxStreak(m, data): 12 | # Write your code here 13 | curStreak = maxStreak = 0 14 | for day in data: 15 | for i in range(m): 16 | if day[i] != "Y": 17 | curStreak = 0 18 | break 19 | else: 20 | curStreak += 1 21 | maxStreak = max(maxStreak, curStreak) 22 | return maxStreak -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 1 - Hackerrank Online Assessment/powerJump.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'powerJump' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts STRING game as parameter. 6 | # 7 | 8 | 9 | def powerJump(game): 10 | # Write your code here 11 | last_value = game[-1] 12 | indices = [] 13 | 14 | for i in range(len(game)): 15 | if game[i] == last_value: 16 | indices.append(i) 17 | 18 | curPow = minPow = indices[0]+1 19 | 20 | for i in range(1, len(indices)): 21 | idx = indices[i] 22 | curPow = indices[i]-indices[i-1] 23 | minPow = max(minPow, curPow) 24 | 25 | return minPow -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 2 - Coding Phone Interview/README.md: -------------------------------------------------------------------------------- 1 | # Round - 2 Technical Phone Interview 2 | 3 | 4 | ## 1. CodePair Coding 5 | ---- 6 | 7 | 1. Given a binary tree, determine if it is a valid binary search tree (BST). 8 | 9 | Assume a BST is defined as follows: 10 | 11 | The left subtree of a node contains only nodes with keys less than the node's key. 12 | The right subtree of a node contains only nodes with keys greater than the node's key. 13 | Both the left and right subtrees must also be binary search trees. 14 | 15 | 16 | 2. Follow-up: 17 | Generalize your code for N-array tree. Make a N-array tree. Given N-array tree validate that it is a binary search tree (BST). 18 | 19 | 3. Follow-up: 20 | Optimize your code. I used flag to stop the recursion. Flag is used for early stop. 21 | 22 | 4. What is the time complexity and space complexity. 23 | 24 | 5. Follow-up: 25 | Can you do it iteratively ?? -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 2 - Coding Phone Interview/isBinarySearchTree.py: -------------------------------------------------------------------------------- 1 | # Time Complexity - O(n) 2 | # Space Complexity - O(1) if we are ignoring the call stack of recursion 3 | # Space Complexity - O(n) if we are considering the call stack of recursion 4 | 5 | 6 | class Node(object): 7 | def __init__(self, value): 8 | self.value = value 9 | # self.left = None 10 | # self.right = None 11 | self.child = [None, None] 12 | 13 | 14 | class Tree(object): 15 | def __init__(self, value): 16 | self.root = Node(value) 17 | 18 | def insert_node(self, value, node): 19 | 20 | if value > node.value: 21 | if node.child[1]: 22 | self.insert_node(value, node.child[1]) 23 | else: 24 | node.child[1] = Node(value) 25 | else: 26 | if node.child[0]: 27 | self.insert_node(value, node.child[0]) 28 | else: 29 | node.child[0] = Node(value) 30 | 31 | 32 | def validate_binary_tree(node): 33 | flag = [True] 34 | return recurse(node, -float("inf"), float("inf"), flag) 35 | 36 | 37 | def recurse(node, min_val, max_val, flag): 38 | if not flag[0]: 39 | return False 40 | 41 | if not node: 42 | return True 43 | 44 | if len(node.child) > 2: 45 | flag[0] = False 46 | return False 47 | 48 | if min_val < node.value < max_val: 49 | return recurse(node.child[0], min_val, node.value, flag) and recurse(node.child[1], node.value, max_val, flag) 50 | else: 51 | flag[0] = False 52 | return False 53 | 54 | 55 | tree = Tree(5) 56 | tree.insert_node(1, tree.root) 57 | tree.insert_node(2, tree.root) 58 | tree.insert_node(3, tree.root) 59 | tree.insert_node(4, tree.root) 60 | tree.insert_node(6, tree.root) 61 | tree.insert_node(7, tree.root) 62 | 63 | is_binary_tree = validate_binary_tree(tree.root) 64 | print(is_binary_tree) 65 | 66 | not_bin_tree = Node(5) 67 | not_bin_tree.child[0] = Node(6) 68 | not_bin_tree.child[1] = Node(7) 69 | 70 | # 5 71 | # / \ 72 | # 6 7 73 | 74 | is_binary_tree = validate_binary_tree(not_bin_tree) 75 | print(is_binary_tree) 76 | 77 | not_bin_tree = Node(5) 78 | not_bin_tree.child[0] = Node(3) 79 | not_bin_tree.child[1] = Node(7) 80 | not_bin_tree.child.append(Node(9)) 81 | 82 | # 5 -- 9 83 | # / \ 84 | # 3 7 85 | is_binary_tree = validate_binary_tree(not_bin_tree) 86 | print(is_binary_tree) 87 | 88 | is_binary_tree = validate_binary_tree(None) 89 | print(is_binary_tree) 90 | -------------------------------------------------------------------------------- /VISA Senior Software Engineer 2019/Round - 3 - Onsite/Design Elevator/elevator.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | class Elevator(object): 4 | def __init__(self): 5 | self.cf = 0 # current floor 6 | self.dirc = "NULL" 7 | self.req = deque([]) 8 | self.reqSet = set([]) 9 | 10 | def in_cmg_req(self, floor): 11 | self.req.append(floor) 12 | self.reqSet.add(floor) 13 | 14 | def process(self): 15 | self.req = sorted(self.req) 16 | 17 | while self.req: 18 | goal_floor = self.req.popleft() 19 | if goal_floor not in self.reqSet: 20 | continue 21 | 22 | self.get_direction(self.cf, goal_floor) 23 | self.go_to_dest(self.cf, goal_floor) 24 | 25 | def get_direction(self, cf, goal_floor): 26 | if cf > goal_floor: 27 | self.dirc = "DOWN" 28 | else: 29 | self.dirc = "UP" 30 | 31 | def go_to_dest(self, cf, goal_floor): 32 | while cf != goal_floor: 33 | if cf in self.reqSet: 34 | self.reqSet.remove(cf) 35 | self.openDoors() 36 | self.closeDoors() 37 | 38 | if self.dirc == "DOWN": 39 | cf -= 1 40 | else: 41 | cf += 1 42 | 43 | else: 44 | self.reqSet.remove(cf) 45 | self.openDoors() 46 | self.closeDoors() 47 | self.dirc = "NULL" 48 | 49 | def openDoors(self): 50 | pass 51 | 52 | def closeDoors(self): 53 | pass -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/DistanceCalculator.java: -------------------------------------------------------------------------------- 1 | // Enter your code here. 2 | import java.util.Scanner; 3 | 4 | abstract class Distance { 5 | protected int feet; 6 | protected float inches; 7 | 8 | abstract public void setFeetAndInches(int feet, float inches); 9 | abstract public int getFeet(); 10 | abstract public float getInches(); 11 | abstract String getDistanceComparison(Distance dist2); 12 | } 13 | 14 | 15 | class DistanceImplementation extends Distance 16 | { 17 | public void setFeetAndInches(int feet, float inches) 18 | { 19 | this.feet = feet; 20 | this.inches = inches; 21 | } 22 | 23 | String getDistanceComparison(Distance dist2) 24 | { 25 | if (((dist2.feet*12)+(dist2.inches))>((this.feet*12)+(this.inches))) 26 | { 27 | return "Second distance is greater."; 28 | } 29 | else if (((dist2.feet*12)+(dist2.inches))<((this.feet*12)+(this.inches))) 30 | { 31 | return "First distance is greater."; 32 | } 33 | else 34 | { 35 | return "Both distances are equal."; 36 | } 37 | } 38 | 39 | public int getFeet() 40 | { 41 | return this.feet; 42 | } 43 | 44 | public float getInches() 45 | { 46 | return this.inches; 47 | } 48 | } 49 | 50 | public class DistanceCalculator { 51 | private static final Scanner scan = new Scanner(System.in); 52 | 53 | public static void main(String[] args) { 54 | Distance dist1 = new DistanceImplementation(); 55 | Distance dist2 = new DistanceImplementation(); 56 | 57 | int feet1 = scan.nextInt(); 58 | float inches1 = scan.nextFloat(); 59 | 60 | int feet2 = scan.nextInt(); 61 | float inches2 = scan.nextFloat(); 62 | 63 | dist1.setFeetAndInches(feet1, inches1); 64 | dist2.setFeetAndInches(feet2, inches2); 65 | 66 | System.out.println(dist1.getDistanceComparison(dist2)); 67 | } 68 | } -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Welcome.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Welcome.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q2_P1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q2_P1.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q2_P2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q2_P2.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q2_P3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q2_P3.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q3.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q4.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q5.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q6.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q6.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q7.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q7.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P1.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P2.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P3.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q8_P4.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P1.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P2.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P3.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P3_expected.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P3_expected.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P4.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P5_expected.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/CodingInterviews/f7a47bc52d9eeab5b11ecc174015e2d94ad007f5/Workday Senior Java Platform Developer/ImageResources/Workday_Q9_P5_expected.JPG -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/TipTop.java: -------------------------------------------------------------------------------- 1 | public class TipTop 2 | { 3 | static final Integer i1 = 1; 4 | final Integer i2 = 2; 5 | Integer i3 = 3; 6 | public static void main(String[] args) 7 | { 8 | final Integer i4 = 4; 9 | Integer i5 = 5; 10 | 11 | class Inner 12 | { 13 | final Integer i6 = 6; 14 | Integer i7 = 7; 15 | Inner() 16 | { 17 | System.out.println(i6+i7); 18 | } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/counts.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | # Returns sum of all factors 5 | # of n. 6 | def sumofoddFactors(n): 7 | # Traversing through all 8 | # prime factors. 9 | res = 1 10 | 11 | # ignore even factors by 12 | # of 2 13 | while n % 2 == 0: 14 | n = n // 2 15 | 16 | for i in range(3, int(math.sqrt(n) + 1)): 17 | 18 | # While i divides n, print 19 | # i and divide n 20 | count = 0 21 | curr_sum = 1 22 | curr_term = 1 23 | while n % i == 0: 24 | count += 1 25 | 26 | n = n // i 27 | curr_term *= i 28 | curr_sum += curr_term 29 | 30 | res *= curr_sum 31 | 32 | # This condition is to 33 | # handle the case when 34 | # n is a prime number. 35 | if n >= 2: 36 | res *= (1 + n) 37 | 38 | return res 39 | 40 | 41 | def counts(numbers): 42 | results = 0 43 | for num in numbers: 44 | results += sumofoddFactors(num) 45 | return results 46 | -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/degreeOfArray.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'degreeOfArray' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts INTEGER_ARRAY arr as parameter. 6 | # 7 | from collections import Counter, defaultdict 8 | 9 | 10 | def degreeOfArray(arr): 11 | # Write your code here 12 | maxDeg = 0 13 | num2count = defaultdict(int) 14 | firstSeen = {} 15 | lastSeen = {} 16 | for idx, num in enumerate(arr): 17 | num2count[num] += 1 18 | if num not in firstSeen: 19 | firstSeen[num] = idx 20 | lastSeen[num] = idx 21 | 22 | maxDeg = max(maxDeg, num2count[num]) 23 | 24 | minLength = float("inf") 25 | for num in num2count: 26 | if num2count[num] == maxDeg: 27 | minLength = min(minLength, (lastSeen[num] - firstSeen[num])) 28 | 29 | return minLength + 1 -------------------------------------------------------------------------------- /Workday Senior Java Platform Developer/regEx.py: -------------------------------------------------------------------------------- 1 | # Write the regular expression 2 | # in the blank space below 3 | from os import environ 4 | from re import compile 5 | from re import match 6 | 7 | regularExpression = "^([a-z]{1,6}_?)([a-z]?[a-z]?[a-z]?[a-z]?)@hackerrank.com$" 8 | 9 | pattern = compile(regularExpression) 10 | 11 | query = int(input()) 12 | result = ['False'] * query 13 | 14 | for i in range(query): 15 | someString = input() 16 | 17 | if pattern.match(someString): 18 | result[i] = 'True' 19 | 20 | print(result) 21 | -------------------------------------------------------------------------------- /Workday Software Development Engineer/README.md: -------------------------------------------------------------------------------- 1 | # Got this problem in HACKERRANK challenge 2 | 3 | 4 | ## 1. Array Reduction 5 | ----- 6 | 7 | 8 | Anna has an array of n integers called sum. 9 | She can reduce the array by 1 element by performig a move. 10 | Each move consists of following three steps: 11 | 1. Pick two different elements. 12 | 2. Remove the two selected elements from array. 13 | 3. Add the sum of the two selected elements to the end of the array. 14 | 15 | Each move has a cost associated with it. 16 | The cost is equal to the sum of the two elements removed from the array during the move. 17 | Anna wishes to calculate the minimum total cost of reducing her array to one element. 18 | 19 | Function Description: 20 | Complete the function `reductionCost`. 21 | The function must return the minimum total cost of reducing the input array to one element. 22 | 23 | `reductionCost` has following parameters: 24 | num[num[0], ..., num[n-1]]: an array of integers. 25 | 26 | Constraints: 27 | - 2 <= n <= 10000. 28 | - 0 <= num[i] <= 100000 29 | 30 | Sample Input 0: 31 | 3 32 | 1 33 | 2 34 | 3 35 | Sample Output 0: 36 | 9 37 | 38 | Explanation 0: 39 | Anna makes the following moves to reduce the num = [1, 2, 3]: 40 | 1. Removes 1 and 2 at cost1 = 1+2 = 3, resulting in num1 = [3, 3] 41 | 1. Removes 3 and 3 at cost2 = 3+3 = 6, resulting in num2 = [6] 42 | When we sum up the cost at each reduction, we get 3+6 = 9 43 | 44 | Sample Input 1: 45 | 3 46 | 4 47 | 6 48 | 8 49 | Sample output 1: 50 | 28 51 | -------------------------------------------------------------------------------- /Workday Software Development Engineer/reductionCost.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'reductionCost' function below. 3 | # 4 | # The function is expected to return an INTEGER. 5 | # The function accepts INTEGER_ARRAY num as parameters: 6 | 7 | 8 | def reductionCost(nums): 9 | # You can also solve this by heap data-structure 10 | # Since this submission got accepted by Hackerrank so I did not use heap 11 | summ = 0 12 | while len(nums) != 0: 13 | nums = sorted(nums) 14 | summ += nums[0]+nums[1] 15 | nums = [nums[0]+nums[1]+nums[2:]] 16 | return summ 17 | --------------------------------------------------------------------------------