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.5k
- Digital Logic 2.1k
- Programming & DS 4k
- Algorithms 3.4k
- Theory of Computation 4.2k
- Compiler Design 1.6k
- Databases 3.1k
- CO & Architecture 2.7k
- Computer Networks 3.1k
- Non GATE 1.1k
- Others 1.4k
- Admissions 501
- Exam Queries 450
- Tier 1 Placement Questions 19
- Job Queries 62
- Projects 12

38,106 questions

45,609 answers

132,247 comments

49,238 users