Skip to content

Repository files navigation

Daily Coding Problem Solutions

This is collection of .Net solutions to problems set by Daily Coding Problems. They are interview questions set by the likes of Google, Facebook, Amazon, etc.


Daily Coding Problem - PrefixMapSum

This problem was asked by Google.

Implement a PrefixMapSum class with the following methods:

  • insert(key: str, value: int): Set a given key's value in the map. If the key already exists, overwrite the value.
  • sum(prefix: str): Return the sum of all values of keys that begin with a given prefix.

For example, you should be able to run the following code:

mapsum.insert("columnar",3)
assert mapsum.sum("col")==3
mapsum.insert("column",2)
assert mapsum.sum("col")==5

Solution

Daily Coding Problem - Rand5()

This problem was asked by Two Sigma.

Using a function rand7() that returns an integer from 1 to 7 (inclusive) with uniform probability, implement a function rand5() that returns an integer from 1 to 5 (inclusive).

Solution

Daily Coding Problem - Binary Tree Deepest Node

This problem was asked by Google.

Given the root of a binary tree, return a deepest node. For example, in the following tree, return d.

 a
/ \
b c
/
d

Solution

Roman Numerals

Write a function to convert Arabic numbers to Roman numerals.

Given a positive integer number (for example, 42), determine its Roman numeral representation as a string (for example, XLII).

Examples:

Simple numbers

ArabicRomanArabicRoman
1I60LX
2II70LXX
3III80LXXX
4IV90XC
5V100C
6VI200CC
7VII300CCC
8VIII400CD
9IX500D
10X600DC
20XX700DCC
30XXX800DCCC
40XL900CM
50L1000M

Composed Numbers

ArabicRomanThousandsCentsTenthsUnits
846DCCCXLVI-DCCXLVI
1999MCMXCIXMCMXCIX
2008MMVIIIMM--VIII

Solution

About

Solutions to Daily Coding Problems

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages