Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,915 members, 7,817,684 topics. Date: Saturday, 04 May 2024 at 05:17 PM

Daily Coding Problem - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Daily Coding Problem (3648 Views)

Come And Solve This Coding Problem / Backend Coding Problem / Daily Coding Leaderboard (2) (3) (4)

(1) (2) (Reply) (Go Down)

Daily Coding Problem by deradees: 10:15pm On May 22, 2019
Let us solve interview problems from dailycodingproblem.com together
Re: Daily Coding Problem by deradees: 10:24pm On May 22, 2019
This problem was asked by Microsoft.
I am finding it difficult to upload the screenshot of the problem so I had to copy it.



Implement 3 stacks using a single list:

class Stack:
def __init__(self):
self.list = []

def pop(self, stack_number):
pass

def push(self, item, stack_number):
pass
Re: Daily Coding Problem by deradees: 10:26pm On May 22, 2019
Here is another one

This problem was asked by Google.

You're given a string consisting solely of (, ), and *. * can represent either a (, ), or an empty string. Determine whether the parentheses are balanced.
Re: Daily Coding Problem by deradees: 10:41pm On May 22, 2019
This question was asked by Google.

Given an N by M matrix consisting only of 1's and 0's, find the largest rectangle containing only 1's and return its area.

For example, given the following matrix:

[[1, 0, 0, 0],
[1, 0, 1, 1],
[1, 0, 1, 1],
[0, 1, 0, 0]]
Re: Daily Coding Problem by deradees: 10:42pm On May 22, 2019
Let's get our hands soiled with code


This problem was asked by Facebook.

You have a large array with most of the elements as zero.

Use a more space-efficient data structure, SparseArray, that implements the same interface:

init(arr, size): initialize with the original large array and size.
set(i, val): updates index at i with val.
get(i): gets the value at index i.
Re: Daily Coding Problem by deradees: 10:44pm On May 22, 2019
This problem was asked by Amazon.

Given a node in a binary search tree, return the next bigger element, also known as the inorder successor.

For example, the inorder successor of 22 is 30.

10
/ \
5 30
/ \
22 35
Re: Daily Coding Problem by deradees: 10:45pm On May 22, 2019
This question was asked by Apple.

Given a binary tree, find a minimum path sum from root to a leaf.

For example, the minimum path in this tree is [10, 5, 1, -1], which has sum 15.

10
/ \
5 5
\ \
2 1
/
-1
Re: Daily Coding Problem by deradees: 10:48pm On May 22, 2019
I think this one is easy


Given a real number n, find the square root of n. For example, given n = 9, return 3.
Re: Daily Coding Problem by deradees: 10:49pm On May 22, 2019
This question was asked by Zillow.

You are given a 2-d matrix where each cell represents number of coins in that cell. Assuming we start at matrix[0][0], and can only move right or down, find the maximum number of coins you can collect by the bottom right corner.

For example, in this matrix

0 3 1 1
2 0 0 4
1 5 3 1
The most we can collect is 0 + 2 + 1 + 5 + 3 + 1 = 12 coins.
Re: Daily Coding Problem by deradees: 10:58pm On May 22, 2019
This problem was asked by Google.

Given a string of words delimited by spaces, reverse the words in string. For example, given "hello world here", return "here world hello"

Follow-up: given a mutable string representation, can you perform this operation in-place?
Re: Daily Coding Problem by tollyboy5(m): 12:03am On May 23, 2019
deradees:
This problem was asked by Google.

Given a string of words delimited by spaces, reverse the words in string. For example, given "hello world here", return "here world hello"

Follow-up: given a mutable string representation, can you perform this operation in-place?
i never knew interview questions for programmers would be hard like this. thanks for sharing this lemme adjust my understanding of manipulating code
shocked

1 Like

Re: Daily Coding Problem by deradees: 2:21am On May 23, 2019
This problem was asked by Microsoft.

Let's represent an integer in a linked list format by having each node represent a digit in the number. The nodes make up the number in reversed order.

For example, the following linked list:

1 -> 2 -> 3 -> 4 -> 5
is the number 54321.

Given two linked lists in this format, return their sum in the same linked list format.

For example, given

9 -> 9
5 -> 2
return 124 (99 + 25) as:

4 -> 2 -> 1
Re: Daily Coding Problem by deradees: 2:23am On May 23, 2019
tollyboy5:

i never knew interview questions for programmers would be hard like this. thanks for sharing this lemme adjust my understanding of manipulating code
shocked

You are welcome sir!
Some are actually easy.
I will share more questions as time unfolds.

1 Like

Re: Daily Coding Problem by deradees: 2:25am On May 23, 2019
This question was asked by Riot Games.

Design and implement a HitCounter class that keeps track of requests (or hits). It should support the following operations:

record(timestamp): records a hit that happened at timestamp
total(): returns the total number of hits recorded
range(lower, upper): returns the number of hits that occurred between timestamps lower and upper (inclusive)
Follow-up: What if our system has limited memory?
Re: Daily Coding Problem by deradees: 2:27am On May 23, 2019
This question was asked by Snapchat.

Given the head to a singly linked list, where each node also has a “random” pointer that points to anywhere in the linked list, deep clone the list.
Re: Daily Coding Problem by deradees: 2:28am On May 23, 2019
The Tower of Hanoi is a puzzle game with three rods and n disks, each a different size.

All the disks start off on the first rod in a stack. They are ordered by size, with the largest disk on the bottom and the smallest one at the top.

The goal of this puzzle is to move all the disks from the first rod to the last rod while following these rules:

You can only move one disk at a time.
A move consists of taking the uppermost disk from one of the stacks and placing it on top of another stack.
You cannot place a larger disk on top of a smaller disk.
Write a function that prints out all the steps necessary to complete the Tower of Hanoi. You should assume that the rods are numbered, with the first rod being 1, the second (auxiliary) rod being 2, and the last (goal) rod being 3.

For example, with n = 3, we can do this in 7 moves:

Move 1 to 3
Move 1 to 2
Move 3 to 2
Move 1 to 3
Move 2 to 1
Move 2 to 3
Move 1 to 3
Re: Daily Coding Problem by deradees: 2:30am On May 23, 2019
This one no be for Tonto Dike lovers


This problem was asked by LinkedIn.

Given a string, return whether it represents a number. Here are the different kinds of numbers:

"10", a positive integer
"-10", a negative integer
"10.1", a positive real number
"-10.1", a negative real number
"1e5", a number in scientific notation
And here are examples of non-numbers:

"a"
"x 1"
"a -2"
"-"
Re: Daily Coding Problem by deradees: 2:31am On May 23, 2019
This problem was asked by Facebook.

Write a function that rotates a list by k elements. For example, [1, 2, 3, 4, 5, 6] rotated by two becomes [3, 4, 5, 6, 1, 2]. Try solving this without creating a copy of the list. How many swap or move operations do you need?
Re: Daily Coding Problem by deradees: 2:32am On May 23, 2019
I will also share questions from cracking the coding interview by Gaayle Laakman McDowell

1 Like

Re: Daily Coding Problem by deradees: 2:33am On May 23, 2019
This problem was asked by Microsoft.

You have n fair coins and you flip them all at the same time. Any that come up tails you set aside. The ones that come up heads you flip again. How many rounds do you expect to play before only one coin remains?

Write a function that, given n, returns the number of rounds you'd expect to play until one coin remains.
Re: Daily Coding Problem by deradees: 2:34am On May 23, 2019
This problem was asked by Google.

Given a set of closed intervals, find the smallest set of numbers that covers all the intervals. If there are multiple smallest sets, return any of them.

For example, given the intervals [0, 3], [2, 6], [3, 4], [6, 9], one set of numbers that covers all these intervals is {3, 6}.
Re: Daily Coding Problem by deradees: 2:35am On May 23, 2019
This problem was asked by Facebook.

Given a binary tree, return the level of the tree with minimum sum.
Re: Daily Coding Problem by deradees: 2:36am On May 23, 2019
This problem was asked by Google.

Given a sorted list of integers, square the elements and give the output in sorted order.

For example, given [-9, -2, 0, 2, 3], return [0, 4, 4, 9, 81].
Re: Daily Coding Problem by deradees: 2:37am On May 23, 2019
This problem was asked by Jane Street.

Generate a finite, but an arbitrarily large binary tree quickly in O(1).

That is, generate() should return a tree whose size is unbounded but finite.
Re: Daily Coding Problem by deradees: 2:38am On May 23, 2019
This problem was asked by Square.

Given a string and a set of characters, return the shortest substring containing all the characters in the set.

For example, given the string "figehaeci" and the set of characters {a, e, i}, you should return "aeci".

If there is no substring containing all the characters in the set, return null.
Re: Daily Coding Problem by deradees: 2:39am On May 23, 2019
This problem was asked by Facebook.

Given an array of numbers representing the stock prices of a company in chronological order and an integer k, return the maximum profit you can make from k buys and sells. You must buy the stock before you can sell it, and you must sell the stock before you can buy it again.

For example, given k = 2 and the array [5, 2, 4, 0, 1], you should return 3.
Re: Daily Coding Problem by deradees: 2:41am On May 23, 2019
This problem was asked by Facebook.

Given a string and a set of delimiters, reverse the words in the string while maintaining the relative order of the delimiters. For example, given "hello/world:here", return "here/world:hello"

Follow-up: Does your solution work for the following cases: "hello/world:here/", "hello//world:here"
Re: Daily Coding Problem by deradees: 2:42am On May 23, 2019
This problem was asked by Dropbox.

What does the below code snippet print out? How can we fix the anonymous functions to behave as we'd expect?

functions = []
for i in range(10):
functions.append(lambda : i)

for f in functions:
print(f())
Re: Daily Coding Problem by deradees: 2:43am On May 23, 2019
This problem was asked by Amazon.

Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".

Implement run-length encoding and decoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. You can assume the string to be decoded is valid.
Re: Daily Coding Problem by deradees: 2:44am On May 23, 2019
This problem was asked by Palantir.

Given a number represented by a list of digits, find the next greater permutation of a number, in terms of lexicographic ordering. If there is not greater permutation possible, return the permutation with the lowest value/ordering.

For example, the list [1,2,3] should return [1,3,2]. The list [1,3,2] should return [2,1,3]. The list [3,2,1] should return [1,2,3].

Can you perform the operation without allocating extra memory (disregarding the input memory)?
Re: Daily Coding Problem by deradees: 2:45am On May 23, 2019
You are in an infinite 2D grid where you can move in any of the 8 directions:

(x,y) to
(x+1, y),
(x - 1, y),
(x, y+1),
(x, y-1),
(x-1, y-1),
(x+1,y+1),
(x-1,y+1),
(x+1,y-1)
You are given a sequence of points and the order in which you need to cover the points. Give the minimum number of steps in which you can achieve it. You start from the first point.

Example:

Input: [(0, 0), (1, 1), (1, 2)]
Output: 2
It takes 1 step to move from (0, 0) to (1, 1). It takes one more step to move from (1, 1) to (1, 2).
Re: Daily Coding Problem by deradees: 2:46am On May 23, 2019
This problem was asked by Google.

Determine whether a doubly linked list is a palindrome. What if it’s singly linked?

For example, 1 -> 4 -> 3 -> 4 -> 1 returns True while 1 -> 4 returns False.

(1) (2) (Reply)

Let's Talk About OpenAI ChatGPT. What's The Future of Developers ? / Internships /jobs For Computer Engineer /scientists / 250 Free Udemy Courses. Yes, Free.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.