FazeelUsmani / Amazon-SDE-Preparation

This repository includes all the interview preparation questions for Amazon SDE role
https://practice.geeksforgeeks.org/batch/Amazon-Test-Series
1.12k stars 291 forks source link

Create 02 allPossibleStrings.cpp #61

Closed Juro221 closed 3 years ago

Juro221 commented 3 years ago

We always have to create 2^(n-1) words, where n is the length of a string. We create all binary numbers consisting of n-1 bits. If there is a 1 in binary number on position j we put space in our word after j-th symbol of word. Time complexity is then O(n * (2^n)).