DESHAW Coding Question – Solved

8 Live
A digital art gallery has an art collection which is represented as a binary string. Each digit in the string represents an artwork and there are two types of artworks: '0' represents a traditional artwork, '1' represents a modern artwork. Your task is to find out the number of ways to choose three artworks in ascending order of their position in the collection, such that no two adjacent selected artworks are of the same type. Example: collection = '01001' The following sequences of artworks match the criterion: - [1, 2, 3], that is, 01001 β†’ 010 - [1, 2, 4], that is, 01001 β†’ 010 - [2, 3, 5], that is, 01001 β†’ 101 - [2, 4, 5], that is, 01001 β†’ 101 The answer is 4. Function Description: Complete the function countWays in the editor below. countWays has the following parameter: string collection: a string that represents the collection Returns: long: the total number of ways to select 3 artworks that meet the criterion Constraints: - 1 ≀ |collection| ≀ 2Γ—10⁡ - Each character in collection is either '0' or '1' Input Format For Custom Testing Sample Case 0 Sample Input For Custom Testing STDIN: 10111 Sample Output: collection = "10111" Explanation: The following sequences of artworks match the criterion: - [1, 2, 3], that is, 10111 β†’ 101 - [1, 2, 4], that is, 10111 β†’ 101 - [1, 2, 5], that is, 10111 β†’ 101

Asked in: DESHAW

Image of the Question

Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| A company is organizing a batch process, where each batch consists of several t… |
| Given a series of integer intervals, determine the size of the smallest set tha… |
| A forklift operator navigates products within an automotive parts warehouse. Th… |
| School renovation Given N classrooms in a school and each classroom has a ca… |
| Number in a range You are given three integers L, R, and K. A number X repre… |
| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |