Where n>=1

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+1 vote

you are not given condition about n.... i assumed it as n>1 or n≽ 2..... because to **start with 'a'** which is **n-1=1**

for n=2 ====> a=1 ---- b=5

for n=3 ====> a=2 ---- b=7

for n=4 ====> a=3 ---- b=9

and so on....

here observe the logic:- **b = 2*a +3** therefore first **push 3 x's** **to the empty stack** and **push 2 x's for each occurrences of 'a'** and **pop 1 'x' for each 'b'** ===> Finally stack is empty when all b's are processed.

note when first b occurred change the state.

- All categories
- General Aptitude 1.3k
- Engineering Mathematics 5.2k
- Digital Logic 2k
- Programming & DS 3.7k
- Algorithms 3.2k
- Theory of Computation 4k
- Compiler Design 1.6k
- Databases 3k
- CO & Architecture 2.6k
- Computer Networks 3k
- Non GATE 1k
- Others 1.3k
- Admissions 486
- Exam Queries 435
- Tier 1 Placement Questions 18
- Job Queries 56
- Projects 9

36,157 questions

43,608 answers

123,961 comments

42,860 users