Amazon Online Assessment 2021 (OA) - Coin Sequence

Amazon Shopping recently launched a new Coin Collection Album. Each page has a coin pasted on it, with either the head or tail side facing upward, represented by 'H'and 'T' respectively. A sequence of coins is called beautiful if all the head-facing coins are pasted before all the tail-facing coins. More formally, a beautiful sequence is a sequence of the form "HH.....TTT".

One of the buyers has a hobby of collecting and organizing coins. The buyer pastes n coins on n pages and then wishes to organize them into a beautiful sequence. Given the initial sequence of coins, find the minimum number of coins that must be flipped to obtain a beautiful sequence.

Note that a sequence containing all head facing coins, or all tail facing coins is also valid.


  • coins = HHTHTT: Flip the fourth coin to obtain the beautiful sequence "HHTTTT". The answer is 1. Note that this is the minimum number of coins that must be flipped to make the coin sequence beautiful.

Solution and Explanations



Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions