Engineering Full Stack Apps with Java and JavaScript
Problems related to sequence generation and finding if an element fits in a sequence.
Generate the below sequence with n elements.
1, 10, 11, 100, 110, 111, 1000.
Note:
Every element in the sequence is a series of 1 or more 1's followed by zero or more 0's.
For example 101 is an invalid element and does not belong to the sequence, but 1, 10, 11, 100, 110, 111, 1000 etc. belong to the sequence.
Hint: Binary sequence of numbers is 1, 10, 11, 100, 101, 110, 111, 1000 etc.
Find if the element belongs to the sequence 4, 40, 44, 400, 440, 444, 4000, without generating the sequence.
Note:
Every element in the sequence is a series of 1 or more 4's followed by zero or more 0's.
For example 404 is an invalid element and does not belong to the sequence, but 4, 40, 44, 400, 440, 444, 4000 etc. belong to the sequence.