Multiple Stacks

Hard Stack: Applications PRO
🔒 Login to Unlock

Problem Statement

Write a C program to implement three stacks in a single fixed-size array efficiently by partitioning the array space.

Input Format

First line contains n queries. Subsequent lines contain stack ID (1, 2, or 3), operation type (1 for push, 2 for pop), and value (if push).

Output Format

Print popped or final values for requested stack inspections.

Constraints

1 <= n <= 100, MAX = 90

Sample Input

6
1 1 10
1 1 20
2 1 30
2 1 40
3 1 50
3 1 60

Sample Output

20
10
40
30
60
50

Explanation

Divide the array buffer into three equal segments to support independent push and pop operations for three separate stacks.

Starter Code

#include <stdio.h>
#include <stdlib.h>

#define MAX 90

int main() {
    int n;
    if (scanf("%d", &n) == 1) {
        // Write your code here to implement multiple stacks in a single array
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used