Dominator

Problem An array A consisting of N integers is given. The dominator of array A is the value that occurs in more than half of the elements of A. For example, consider array A such that The dominator of A is 3 because it occurs in 5 out of 8 elements of A (namely in those with indices 0, 2, 4, 6 and…

Read More

All You Need To Know About Event Loop (2)

Event Loop Let’s check the code above. Assuming the ‘waitForMessage’ function behaves synchronously. It means it runs an infinite loop and waits for a message, and if there is a message, process the next one. In other words, the is not a component of the engine, but manages which job to pile up…

Read More

Stone Wall

Problem You are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is specified by an array H of N positive integers. HI is the height of the wall from…

Read More

Nesting

Problem A string S consisting of N characters is called properly nested if: S is empty; S has the form “(U)” where U is a properly nested string; S has the form “VW” where V and W are properly nested strings. For example, string ”(()(())())” is properly nested but string ”())” isn’t. Write a…

Read More

Fish

Problem You are given two non-empty arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q…

Read More
Page 18 Of 26