# Papildomos užduotys
# Vaizdo pamoka
# Daily Coding Problem
Eikite adresu dailycodingproblem.com (opens new window) ir prenumeruokite užduotis.
Kiekvieną dieną į pašto dėžutę gausite po programavimo problemą iš tokių organizacijų kaip Google, Facebook, Airbnb ir t.t.
Spręskite gautas užduotis. Taip tobulėsite kiekvieną dieną.
Taip pat, galima nusipirkti knygą su užduotimis ir jų sprendimais. Daugiau informacijos rasite čia (opens new window).
Kelios pavyzdinės užduotys, gaunamos iš Daily Coding Problem pateiktos žemiau.
# Pavyzdinė užduotis 1
This problem was recently asked by Google.
Given a list of numbers and a number
k
, return whether any two numbers from the list add up tok
.For example, given
[10, 15, 3, 7]
andk
of17
, returntrue
since10 + 7
is17
.Bonus: Can you do this in one pass?
# Pavyzdinė užduotis 2
This problem was asked by 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 ati
.For example, if our input was
[1, 2, 3, 4, 5]
, the expected output would be[120, 60, 40, 30, 24]
. If our input was[3, 2, 1]
, the expected output would be[2, 3, 6]
.Follow-up: what if you can't use division?
# Pavyzdinė užduotis 3
This problem was asked by 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.
For example, the input
[3, 4, -1, 1]
should give2
. The input[1, 2, 0]
should give3
.You can modify the input array in-place.
# Pavyzdinė užduotis 4
This problem was asked by Facebook.
Given the mapping
a = 1, b = 2, ... z = 26
, and an encoded message, count the number of ways it can be decoded.For example, the message
'111'
would give3
, since it could be decoded as'aaa'
,'ka'
, and'ak'
.You can assume that the messages are decodable. For example,
'001'
is not allowed.
# Pavyzdinė užduotis 5
This problem was asked by Airbnb.
Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be
0
ornegative
.For example,
[2, 4, 6, 2, 5]
should return13
, since we pick2
,6
, and5
.[5, 1, 1, 5]
should return10
, since we pick5
and5
.Follow-up: Can you do this in
O(N)
time and constant space?
# Pavyzdinė užduotis 6
This problem was asked by Amazon.
There exists a staircase with
N
steps, and you can climb up either1
or2
steps at a time. GivenN
, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters.For example, if
N
is4
, then there are5
unique ways:
1, 1, 1, 1
2, 1, 1
1, 2, 1
1, 1, 2
2, 2
What if, instead of being able to climb
1
or2
steps at a time, you could climb any number from a set of positive integersX
? For example, ifX = {1, 3, 5}
, you could climb1
,3
, or5
steps at a time.