admin

[Solution] Valleys and Hills solution codechef

Valleys and Hills solution codechef Chef built a binary string SS that has exactly NN hills and MM valleys. A hill is any index 1<i<|S|1<i<|S| such that both its neighbors are strictly smaller than it, i.e, Si−1<SiSi−1<Si and Si+1<SiSi+1<Si. A valley is any index 1<i<|S|1<i<|S| such that both its neighbors are strictly larger than it, i.e, Si−1>SiSi−1>Si and Si+1>SiSi+1>Si. Chef thinks that his string SS is the shortest among all binary strings with NN hills and MM valleys. You don’t quite …

[Solution] Valleys and Hills solution codechef Read More »

[Solution] List of Lists solution codechef

List of Lists solution codechef You are given a positive integer NN and an array AA of size NN. There are NN lists L1,L2…LNL1,L2…LN. Initially, Li=[Ai]Li=[Ai]. You can perform the following operation any number of times as long as there are at least 22 lists: Select 22 (non-empty) lists LiLi and LjLj (i≠ji≠j) Append LjLj to LiLi and remove the list LjLj. Note that this means LjLj cannot be chosen in any future operation. Find the minimum number of …

[Solution] List of Lists solution codechef Read More »

[Solution] Utkarsh and Placement tests solution codechef

Utkarsh and Placement tests solution codechef Utkarsh is currently sitting for placements. He has applied to three companies named A,BA,B, and CC. You know Utkarsh’s order of preference among these 33 companies, given to you as characters first, second, and third respectively (where first is the company he prefers most). You also know that Utkarsh has received offers from exactly two of these three companies, …

[Solution] Utkarsh and Placement tests solution codechef Read More »

[Solution] Tree Coloring solution codeforces

Tree Coloring solution codeforces You are given a rooted tree consisting of 𝑛n vertices numbered from 11 to 𝑛n. The root of the tree is the vertex 11. You have to color all vertices of the tree into 𝑛n colors (also numbered from 11 to 𝑛n) so that there is exactly one vertex for each color. Let 𝑐𝑖ci be the color of vertex 𝑖i, and 𝑝𝑖pi be the parent of vertex 𝑖i in …

[Solution] Tree Coloring solution codeforces Read More »