Archive / 2022 / Selection Test
Just Pens and Pencils
Rangi is a grade 1 student. One day as an activity her teacher gave them a number of pens and pencils and asked them to make a pattern that had the following rules.
- No two pencils can be adjacent
- No three pens can be adjacent
- The pattern can start from either pencil or pen
Rangi was enthusiastic and fascinated. Later at home, she tried different combinations but she couldn’t form the required pattern. Frustrated she asked her brother Nisura for help. Nisura being a computer science undergraduate he determined to write a computer program to generate patterns.
In his computer programme pens are denoted in “1” and pencils are denoted in “0”.
Note: If there are multiple solutions, you can print any of them.
Input Format
Two space separated integers n and m, denoting the number of pencils and the number of pens respectively.
Output Format
Print the pattern on a single line. If no such pattern is found print -1.
Constraints
- 1 \(\leq\) n \(\leq\) 1,000,000
- 1 \(\leq\) m \(\leq\) 1,000,000
Limits
- Time Limit: 1s
- Memory Limit: 256MB
Sample Input 0
1 2
Sample Output 0
101
Sample Input 1
4 7
Sample Output 1
11011010101
Sample Input 2
1 6
Sample Output 2
-1
Open on HackerRank ↗ · Markdown source · Back to the archive