## #7

Day 7

Photo by Glenn Carstens-Peters on Unsplash

## The Problem

Read More »#7Given a linked list, uniformly shuffle the nodes. What if we want to prioritize space over time?

https://dailycodingproblem.com

Day 7

Photo by Glenn Carstens-Peters on Unsplash

Read More »#7Given a linked list, uniformly shuffle the nodes. What if we want to prioritize space over time?

https://dailycodingproblem.com

Day 6

Photo by Dominik Scythe on Unsplash

Read More »#6Write an algorithm that finds the total number of set bits in all integers between

https://dailycodingproblem.com`1`

and`N`

Day 5

Photo by Jeremy Thomas on Unsplash

Read More »#5You have

`N`

stones in a row, and would like to create from them a pyramid. This pyramid should be constructed such that the height of each stone increases by one until reaching the tallest stone, after which the heights decrease by one. In addition, the start and end stones of the pyramid should each be one stone high.You can change the height of any stone by paying a cost of

`1`

unit to lower its height by`1`

, as many times as necessary. Given this information, determine the lowest cost method to produce this pyramid.For example, given the stones

https://dailycodingproblem.com`[1, 1, 3, 3, 2, 1]`

, the optimal solution is to pay`2`

to create`[0, 1, 2, 3, 2, 1]`

.

Day 4

Photo by Viktor Forgacs on Unsplash

Read More »#4An imminent hurricane threatens the coastal town of Codeville. If at most two people can fit in a rescue boat, and the maximum weight limit for a given boat is k, determine how many boats will be needed to save everyone.

For example, given a population with weights [100, 200, 150, 80] and a boat limit of 200, the smallest number of boats required will be three.

https://dailycodingproblem.com

Day 3

Photo by Mateusz Delegacz on Unsplash

A wall consists of several rows of bricks of various integer lengths and uniform height. Your goal is to find a vertical line going from the top to the bottom of the wall that cuts through the fewest number of bricks. If the line goes through the edge between two bricks, this does not count as a cut.

For example, suppose the input is as follows, where values in each row represent the lengths of bricks in that row

```
[[3, 5, 1, 1],
[2, 3, 3, 2],
[5, 5],
[4, 4, 2],
[1, 3, 3, 3],
[1, 1, 6, 1, 1]]
```

Read More »#3The best we can we do here is to draw a line after the eighth brick, which will only require cutting through the bricks in the third and fifth row.

https://dailycodingproblem.com

Given an input consisting of brick lengths for each row such as the one above, return the fewest number of bricks that must be cut to create a vertical line.

Day 2

Photo by Chris Barbalis on Unsplash

Two nodes in a binary tree can be called cousins if they are on the same level of the tree but have different parents. For example, in the following diagram

`4`

and`6`

are cousins.

```
1
/ \
2 3
/ \ \
4 5 6
```

Read More »#2Given a binary tree and a particular node, find all cousins of that node.

https://dailycodingproblem.com

Day 1

Read More »#1You are given an array representing the heights of neighboring buildings on a city street, from east to west. The city assessor would like you to write an algorithm that returns how many of these buildings have a view of the setting sun, in order to properly value the street.

For example, given the array

https://dailycodingproblem.com`[3, 7, 8, 3, 6, 1]`

, you should return`3`

, since the top floors of the buildings with heights`8`

,`6`

, and`1`

all have an unobstructed view to the west.