Practice Challenge

Hard Stack: Advanced Applications PRO
🔒 Login to Unlock

Problem Statement

Write a C program to implement two stacks using a single shared array of size MAX without overflowing unless total elements exceed MAX.

Input Format

Test commands for push1, push2, pop1, pop2 and printing stack contents.

Output Format

Print elements of Stack 1 and Stack 2 as requested.

Constraints

MAX = 100

Sample Input

4
1 10
1 20
2 30
2 40

Sample Output

20 10
40 30

Explanation

Initialize top1 = -1 and top2 = MAX. Grow Stack 1 from left to right and Stack 2 from right to left within the same array buffer.

Starter Code

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

#define MAX 100

struct TwoStacks {
    int arr[MAX];
    int top1;
    int top2;
};

int main() {
    int n;
    if (scanf("%d", &n) == 1) {
        // Write your code here to implement two stacks in one array practice challenge
    }
    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