Skip to content

This repository is a collection of solutions for Daily Coding Problem problems.

Notifications You must be signed in to change notification settings

peterwzhang/DCP-Solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DCP-Solutions

This repository is a collection of solutions for Daily Coding Problem problems.
"A daily coding problem a day keeps the unemployment away..."

Authors

  • Madeline Moore - mcmoore11
    • told Peter about the DCPs... he had already been subscribed for over a year
    • managed all folders
  • Peter Zhang - PeterTheAmazingAsian
    • made the readme lol
    • subcribed to DCP for way too long

Solutions

Below we have a table of all the DCPs (1-399). The table contains the question number/day, the company that asked the question, a brief description, difficulty, and a link to goto the corresponding folder. There are also two additional columns to show who has completed which problems and in which languages.

Day Company Description Difficulty Madeline Peter Link
001 Google Given a list of numbers and a number k, return whether any two numbers from the list add up to k. Easy Python C++, Python go
002 Uber Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. Hard Python C++, Python go
003 Google Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree. Medium - C++, Python go
004 Stripe Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. Hard - C++, Python go
005 Jane Street Implement car and cdr. cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. Medium - C++, Python go
006 Google Implement an XOR linked list; it has an add(element) which adds the element to the end, and a get(index) which returns the node at index. Hard - C++ go
007 Facebook Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded. Medium - - go
008 Google Given the root to a binary tree, count the number of unival subtrees. Easy - C++ go
009 Airbnb Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. Hard - - go
010 Apple Implement a job scheduler which takes in a function f and an integer n, and calls f after n milliseconds. Medium - - go
011 Twitter Implement an autocomplete system. That is, given a query string s and a set of all possible query strings, return all strings in the set that have s as a prefix. Medium - C++ go
012 Amazon There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters. Hard - C++ go
013 Amazon Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters. Hard - - go
014 Google The area of a circle is defined as πr^2. Estimate π to 3 decimal places using a Monte Carlo method. Medium - C++ go
015 Facebook Given a stream of elements too large to store in memory, pick a random element from the stream with uniform probability. Medium - - go
016 Twitter You run an e-commerce website and want to record the last N order ids in a log. Implement a data structure to accomplish this Easy - - go
017 Google Given a string representing the file system in the above format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0. Hard - - go
018 Google Given an array of integers and a number k, where 1 <= k <= length of the array, compute the maximum values of each subarray of length k. Hard - - go
019 Facebook Goal of minimizing cost while ensuring that no two neighboring houses are of the same color. Given an N by K matrix where the nth row and kth column represents the cost to build the nthhouse with kth color, return the minimum cost which achieves this goal. Medium - - go
020 Google Given two singly linked lists that intersect at some point, find the intersecting node. The lists are non-cyclical. Easy - - go
021 Snapchat Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required. Easy - - go
022 Microsoft Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list. Medium - C++ go
023 Google You are given an M by N matrix consisting of booleans that represents a board. Each True boolean represents a wall. Each False boolean represents a tile you can walk on. Given this matrix, a start coordinate, and an end coordinate, return the minimum number of steps required to reach the end coordinate from the start. Easy - - go
024 Google Implement locking in a binary tree. A binary tree node can be locked or unlocked only if all of its descendants or ancestors are not locked. Medium - C++ go
025 Facebook Implement regular expression matching with the following special characters: . and * Hard - - go
026 Google - Medium - - go
027 Facebook - Easy - - go
028 Palantir - Medium - - go
029 Amazon - Easy - - go
030 Facebook - Medium - - go
031 Google Given two strings, compute the edit distance between them. Easy - C++ go
032 Jane Street - Hard - - go
033 Microsoft - Easy - - go
034 Quora - Medium - - go
035 Google - Hard - - go
036 Dropbox - Medium - - go
037 Google The power set of a set is the set of all its subsets. Write a function that given a set, generates its power set. Easy - C++ go
038 Microsoft - Hard - - go
039 Dropbox - Medium - - go
040 Google - Hard - - go
041 Facebook - Medium - - go
042 Google - Hard - - go
043 Amazon - Easy - - go
044 Google - Medium - - go
045 Two Sigma - Easy - - go
046 Amazon - Hard - - go
047 Facebook - Easy - - go
048 Google - Medium - - go
049 Amazon Given an array of numbers, find the maximum sum of any contiguous subarray of the array. Medium - C++ go
050 Microsoft - Easy - - go
051 Facebook - Medium - - go
052 Google - Hard - - go
053 Apple Implement a queue using two stacks. Medium - C++ go
054 Dropbox - Hard - - go
055 Microsoft - Easy - - go
056 Google - Medium - - go
057 Amazon - Medium - - go
058 Amazon Given such an array, find the index of the element in the array in faster than linear time. Medium - C++ go
059 Google - Hard - - go
060 Facebook - Medium - - go
061 Google - Medium - - go
062 Facebook - Medium - - go
063 Microsoft - Easy - - go
064 Google - Hard - - go
065 Amazon Given a N by M matrix of numbers, print out the matrix in a clockwise spiral. Easy - C++ go
066 Square - Medium - - go
067 Google - Hard - - go
068 Google - Medium - - go
069 Facebook Given a list of integers, return the largest product that can be made by multiplying any three integers. Easy - C++ go
070 Microsoft - Easy - - go
071 Two Sigma - Easy - - go
072 Google - Hard - - go
073 Google - Easy - - go
074 Apple Given integers N and X, write a function that returns the number of times X appears as a value in an N by N multiplication table. Medium - C++ go
075 Microsoft - Hard - - go
076 Google - Medium - - go
077 Snapchat - Easy - - go
078 Google - Medium - - go
079 Facebook - Medium - - go
080 Google - Easy - - go
081 Yelp - Easy - - go
082 Microsoft - Easy - - go
083 Google - Medium - - go
084 Amazon - Medium - - go
085 Facebook - Medium - - go
086 Google - Medium - - go
087 Uber - Hard - - go
088 ContextLogic - Medium - - go
089 LinkedIn - Medium - - go
090 Google - Medium - - go
091 Dropbox Fix the code snippet to print 0-9 Easy - Python go
092 Airbnb - Hard - - go
093 Apple - Hard - - go
094 Google - Easy - - go
095 Palantir - Hard - - go
096 Microsoft - Easy - - go
097 Stripe - Medium - - go
098 Coursera - Easy - - go
099 Microsoft - Medium - - go
100 Google - Easy - - go
101 Alibaba - Easy - - go
102 Lyft - Medium - - go
103 Square - Medium - - go
104 Google - Easy - - go
105 Facebook - Easy - - go
106 Pinterest - Medium - - go
107 Microsoft - Easy - - go
108 Google - Easy - - go
109 Cisco - Medium - - go
110 Facebook - Medium - - go
111 Google - Hard - - go
112 Twitter - Hard - - go
113 Google - Medium - - go
114 Facebook - Hard - - go
115 Google - Hard - - go
116 Jane Street - Medium - - go
117 Facebook - Easy - - go
118 Google - Easy - - go
119 Google - Medium - - go
120 Microsoft - Medium - - go
121 Google - Hard - - go
122 Zillow - Medium - - go
123 LinkedIn - Hard - - go
124 Microsoft - Easy - - go
125 Google - Easy - - go
126 Facebook Write a function that rotates a list by k elements. Medium - C++ go
127 Microsoft Given two linked lists in this format, return their sum in the same linked list format. Easy - C++ go
128 None - Medium - - go
129 None - Medium - - go
130 Facebook - Medium - - go
131 Snapchat - Medium - - go
132 Riot Games - Easy - - go
133 Amazon - Medium - - go
134 Facebook - Easy - - go
135 Apple - Easy - - go
136 Google - Medium - - go
137 Amazon - Medium - - go
138 Google - Hard - - go
139 Google - Medium - - go
140 Facebook - Medium - - go
141 Microsoft - Hard - - go
142 Google - Hard - - go
143 Amazon - Medium - - go
144 Google - Medium - - go
145 Google - Easy - - go
146 BufferBox - Medium - - go
147 None - Hard - - go
148 Apple - Medium - - go
149 Goldman Sachs - Hard - - go
150 LinkedIn - Hard - - go
151 None - Medium - - go
152 Triplebyte - Medium - - go
153 None - Hard - - go
154 Amazon - Easy - - go
155 MongoDB - Medium - - go
156 Facebook - Medium - - go
157 Amazon - Easy - - go
158 Slack - Medium - - go
159 Google Given a string, return the first recurring character in it, or null if there is no recurring character. Easy - C++ go
160 Uber - Hard - - go
161 Facebook - Easy - - go
162 Square - Medium - - go
163 Jane Street - Hard - - go
164 Google - Medium - - go
165 Google - Medium - - go
166 Uber - Medium - - go
167 Airbnb - Hard - - go
168 Facebook - Medium - - go
169 Google - Medium - - go
170 Facebook - Medium - - go
171 Amazon - Easy - - go
172 Dropbox - Medium - - go
173 Stripe - Easy - - go
174 Microsoft - Medium - - go
175 Google - Easy - - go
176 Bloomberg - Easy - - go
177 Airbnb - Easy - - go
178 Two Sigma Find the expected values of 5->6 and 5->5 dice games. Hard - C++ go
179 Google - Medium - - go
180 Google Given a stack of N elements, interleave the first half of the stack with the second half reversed using only one other queue. This should be done in-place. Medium - C++ go
181 Google - Hard - - go
182 Facebook - Medium - - go
183 Twitch - Hard - - go
184 Amazon - Easy - - go
185 Google - Easy - - go
186 Microsoft - Hard - - go
187 Google - Easy - - go
188 Google - Medium - - go
189 Google Given an array of elements, return the length of the longest subarray where all its elements are distinct. Easy - C++ go
190 Facebook Given a circular array, compute its maximum subarray sum in O(n) time. A subarray can be empty, and in this case the sum is 0. Medium - C++ go
191 Stripe - Easy - - go
192 Google - Medium - - go
193 Affirm - Hard - - go
194 Facebook - Easy - - go
195 Google - Hard - - go
196 Apple - Easy - - go
197 Amazon - Easy - - go
198 Google - Medium - - go
199 Facebook - Hard - - go
200 Microsoft - Hard - - go
201 Google - Easy - - go
202 Palantir - Easy - - go
203 Uber - Medium - - go
204 Amazon - Easy - - go
205 IBM - Easy - - go
206 Twitter Given an array and a permutation, apply the permutation to the array. Easy - C++ go
207 Dropbox - Medium - - go
208 LinkedIn - Medium - - go
209 YouTube - Hard - - go
210 Apple - Easy - - go
211 Microsoft - Medium - - go
212 Dropbox - Easy - - go
213 Snapchat - Medium - - go
214 Stripe Given an integer n, return the length of the longest consecutive run of 1s in its binary representation. Easy - C++ go
215 Yelp - Medium - - go
216 Facebook - Medium - - go
217 Oracle - Hard - - go
218 Yahoo - Medium - - go
219 Salesforce - Hard - - go
220 Square - Medium - - go
221 Zillow - Easy - - go
222 Quora - Medium - - go
223 Palantir - Hard - - go
224 Amazon - Easy - - go
225 Bloomberg - Easy - - go
226 Airbnb - Hard - - go
227 Facebook - Easy - - go
228 Twitter - Medium - - go
229 Flipkart - Medium - - go
230 Goldman Sachs - Medium - - go
231 IBM - Easy - - go
232 Google - Easy - - go
233 Apple Implement the function fib(n), which returns the nth number in the Fibonacci sequence, using only O(1) space. Easy - C++ go
234 Microsoft - Hard - - go
235 Facebook - Hard - - go
236 Nvidia - Medium - - go
237 Amazon - Easy - - go
238 MIT - Hard - - go
239 Uber - Medium - - go
240 Spotify - Hard - - go
241 Palantir - Easy - - go
242 Twitter - Hard - - go
243 Etsy - Medium - - go
244 Square - Easy - - go
245 Yelp - Medium - - go
246 Dropbox - Medium - - go
247 PayPal - Easy - - go
248 Nvidia - Hard - - go
249 Salesforce - Hard - - go
250 Google - Medium - - go
251 Amazon - Medium - - go
252 Palantir - Easy - - go
253 PayPal - Medium - - go
254 Yahoo - Medium - - go
255 Microsoft - Easy - - go
256 Fitbit - Medium - - go
257 WhatsApp - Easy - - go
258 Morgan Stanley - Easy - - go
259 Two Sigma - Hard - - go
260 Pinterest - Medium - - go
261 Amazon - Easy - - go
262 Mozilla - Medium - - go
263 Nest - Medium - - go
264 LinkedIn - Hard - - go
265 Atlassian - Easy - - go
266 Pivotal - Easy - - go
267 Oracle - Hard - - go
268 Indeed - Medium - - go
269 Microsoft - Easy - - go
270 Twitter - Medium - - go
271 Netflix - Hard - - go
272 Spotify - Medium - - go
273 Apple A fixed point in an array is an element whose value is equal to its index. Given a sorted array of distinct elements, return a fixed point, if one exists. Otherwise, return False. Easy - C++ go
274 Facebook - Hard - - go
275 Epic - Medium - - go
276 Dropbox - Hard - - go
277 Google - Easy - - go
278 Amazon - Easy - - go
279 Twitter - Easy - - go
280 Pandora - Easy - - go
281 LinkedIn - Medium - - go
282 Netflix - Easy - - go
283 Google - Easy - - go
284 Yext - Medium - - go
285 Mailchimp - Medium - - go
286 VMware - Hard - - go
287 Quora - Medium - - go
288 Salesforce - Medium - - go
289 Google - Hard - - go
290 Facebook - Easy - - go
291 Glassdoor - Medium - - go
292 Twitter - Hard - - go
293 Uber - Hard - - go
294 Square - Medium - - go
295 Stitch Fix - Medium - - go
296 Etsy - Hard - - go
297 Amazon - Medium - - go
298 Google - Easy - - go
299 Samsung - Medium - - go
300 Uber - Easy - - go
301 Triplebyte - Medium - - go
302 Uber - Medium - - go
303 Microsoft - Easy - - go
304 Two Sigma - Hard - - go
305 Amazon - Easy - - go
306 Palantir - Medium - - go
307 Oracle - Easy - - go
308 Quantcast - Hard - - go
309 Walmart Labs - Medium - - go
310 Pivotal - Easy - - go
311 Sumo Logic Given an unsorted array, in which all elements are distinct, find a "peak" element in O(log N) time. Easy - C++ go
312 Wayfair - Easy - - go
313 Citrix - Hard - - go
314 Spotify - Medium - - go
315 Google - Easy - - go
316 Snapchat - Medium - - go
317 Yahoo - Medium - - go
318 Apple - Hard - - go
319 Airbnb - Hard - - go
320 Amazon - Medium - - go
321 PagerDuty - Easy - - go
322 Flipkart - Medium - - go
323 Dropbox - Medium - - go
324 Amazon - Easy - - go
325 Jane Street - Easy - - go
326 Netflix - Hard - - go
327 Salesforce - Easy - - go
328 Facebook - Medium - - go
329 Amazon - Hard - - go
330 Dropbox - Hard - - go
331 LinkedIn - Medium - - go
332 Jane Street - Easy - - go
333 Pinterest - Medium - - go
334 Twitter Write a function that plays the 24 game. Easy - C++ go
335 Google - Hard - - go
336 Microsoft - Medium - - go
337 Apple - Hard - - go
338 Facebook - Medium - - go
339 Microsoft - Easy - - go
340 Google - Easy - - go
341 Google - Easy - - go
342 Stripe - Medium - - go
343 Google - Medium - - go
344 Adobe - Hard - - go
345 Google - Medium - - go
346 Airbnb - Medium - - go
347 Yahoo You are given a string of length N and a parameter k. The string can be manipulated by taking one of the first k letters and moving it to the end. Easy - C++ go
348 Zillow - Easy - - go
349 Grammarly - Hard - - go
350 Uber - Medium - - go
351 Quora - Hard - - go
352 Palantir - Easy - - go
353 Square - Medium - - go
354 Google - Hard - - go
355 Airbnb - Hard - - go
356 Netflix - Hard - - go
357 LinkedIn - Hard - - go
358 Dropbox - Hard - - go
359 Slack - Easy - - go
360 Spotify - Medium - - go
361 Facebook - Medium - - go
362 Twitter - Easy - - go
363 Squarespace - Medium - - go
364 Facebook - Medium - - go
365 Google - Hard - - go
366 Flexport - Medium - - go
367 Two Sigma - Medium - - go
368 Google - Hard - - go
369 Two Sigma - Medium - - go
370 Postmates - Easy - - go
371 Google - Hard - - go
372 Amazon Write a function that takes a natural number as input and returns the number of digits the input has. Don't use any loops. Easy - C++ go
373 Facebook - Hard - - go
374 Amazon - Hard - - go
375 Google - Medium - - go
376 Google - Easy - - go
377 Microsoft - Hard - - go
378 Coinbase - Medium - - go
379 Microsoft Given a string, generate all possible subsequences of the string. Easy - C++ go
380 Nextdoor - Medium - - go
381 Paypal - Easy - - go
382 Google - Easy - - go
383 Gusto - Medium - - go
384 WeWork - Hard - - go
385 Apple - Medium - - go
386 Twitter - Easy - - go
387 Amazon - Medium - - go
388 Airtable - Medium - - go
389 Google - Hard - - go
390 Two Sigma - Medium - - go
391 Facebook - Hard - - go
392 Google - Hard - - go
393 Airbnb - Medium - - go
394 Uber Given a binary tree and an integer k, return whether there exists a root-to-leaf path that sums up to k. Easy - C++ go
395 Robinhood - Medium - - go
396 Google - Hard - - go
397 Microsoft - Medium - - go
398 Amazon - Medium - - go
399 Facebook - Hard - - go

Releases

No releases published

Packages

No packages published