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.4k
- Engineering Mathematics 5.9k
- Digital Logic 2.3k
- Programming & DS 4.2k
- Algorithms 3.7k
- Theory of Computation 4.6k
- Compiler Design 1.7k
- Databases 3.4k
- CO & Architecture 2.9k
- Computer Networks 3.3k
- Non GATE 1.2k
- Others 1.3k
- Admissions 506
- Exam Queries 482
- Tier 1 Placement Questions 22
- Job Queries 64
- Projects 15

40,861 questions

47,532 answers

145,984 comments

62,293 users