Recursion Challenge

Hard Recursion PRO
🔒 Login to Unlock

Problem Statement

Write a C program using recursion to solve the subset sum problem: determine if there exists a subset of array elements that adds up to a given target sum (print 1 if possible, 0 otherwise).

Input Format

First line: n and target sum. Second line: n array elements.

Output Format

Print 1 if subset sum exists, else 0.

Constraints

1 <= n <= 15, target <= 1000

Sample Input

5 9
3 34 4 12 5

Sample Output

1

Explanation

Recursively explore two choices for each element: either include the current element in the subset or exclude it.

Starter Code

#include <stdio.h>

int subsetSum(int arr[], int n, int target) {
    // Write your recursive logic here
}

int main() {
    int n, target;
    if (scanf("%d %d", &n, &target) == 2) {
        int arr[15];
        for (int i = 0; i < n; i++) {
            scanf("%d", &arr[i]);
        }
        printf("%dn", subsetSum(arr, n, target));
    }
    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