2 views
24 Jan 2026
Read n pairs. Using recursion function back(pos,open,close), count how many balanced strings are possible. Output count....
3 views
24 Jan 2026
Read n and n integers (n...
3 views
24 Jan 2026
Read a b m, write function modpow(a,b,m) using binary exponent and output a^b mod m....
2 views
24 Jan 2026
Read n intervals [l,r]. Write function merge(intervals) and output merged intervals sorted....
2 views
24 Jan 2026
Read an undirected graph with n nodes and m edges and two nodes s and t. Use helper function bfs to output shortest distance (edges count) or -1....
4 views
24 Jan 2026
Read n integers. Use function mergesort_count(arr) to return inversion count and output it....
3 views
24 Jan 2026
Read n commands: PUSH x, POP, TOP. Use functions do_push, do_pop, do_top on a stack and output TOP outputs (or EMPTY)....
2 views
24 Jan 2026
Read a string s (lowercase) and q queries l r (1-based). Use helper function to build prefix hashes and answer hash values mod 1000000007....
3 views
24 Jan 2026
Read n integers and q queries. Two types: 1 i x means set a[i]=x, 2 l r means output sum of a[l..r] (1-based). Use functions build, update, query....
2 views
24 Jan 2026
Read two integers a and b. Write a function add(a,b) and output add(a,b)....
2 views
24 Jan 2026
Read two integers a and b. Write a function mx(a,b) that returns bigger value (if equal return same). Output result....
2 views
24 Jan 2026
Read one integer n. Create function ab(n) and output absolute value....
2 views
24 Jan 2026
Radius r is provided. Make function area(r)=pi*r*r and output with 2 decimals. Use pi=3.141592653589793....
2 views
24 Jan 2026
One non-negative integer n is provided. Make function digits(n) and output digit count (for n=0 count is 1)....
2 views
24 Jan 2026
Read one integer n. Make function fact(n) and output n!...
3 views
24 Jan 2026
Read one integer n. Make function fib(n) that returns nth Fibonacci (0-index: fib(0)=0,fib(1)=1). Output fib(n)....
4 views
24 Jan 2026
Read two integers a and b. Write function gcd(a,b) using Euclid and output it (always non-negative)....
2 views
24 Jan 2026
Read one integer n. Write function is_prime(n) and output YES if prime else NO....
2 views
24 Jan 2026
One line string s is provided. Write function vowel_count(s) and output number of vowels....
2 views
24 Jan 2026
Read n and n integers. Write function sum_sq(arr) to return sum of squares and output it....
2 views
24 Jan 2026
Read n names (one per line). Make function norm(name) which trims spaces and converts to Title Case (first letter uppercase, rest lowercase per word). Output normalized names....
7 views
24 Jan 2026
Read a b and op (ADD/SUB/MUL). Create function apply(a,b,op) and output result....
2 views
24 Jan 2026
Read q queries, each query is n. Make a fib function and answer all queries fast using memoization....
3 views
24 Jan 2026
Read n integers, write function minmax(arr) returning (min,max). Output min and max....
2 views
24 Jan 2026
Read two integers a and b. Write gcd and lcm functions. Output lcm(a,b). If any is 0, lcm is 0....
3 views
24 Jan 2026
One line sentence is provided. Write function rev_words(s) that reverses word order. Output output....
4 views
24 Jan 2026
Read two strings s and p. Write function count_occ(s,p) and output number of occurrences (overlap allowed)....
2 views
24 Jan 2026
Input has one integer n is provided (non-negative). Write recursive function sumdig(n). Output result....
2 views
24 Jan 2026
Read integers a and b (b>=0), write recursive function powr(a,b) and output a^b....
2 views
24 Jan 2026
Read n integers. Write function only_even(arr) that returns list of even numbers in same order. Output them space-separated, if none output EMPTY....
2 views
24 Jan 2026
Read n integers and chunk size k. Write function chunks(arr,k) that prints each chunk sum in new line....
3 views
24 Jan 2026
Read n integers and q queries (l r, 1-based). Write function build_prefix(arr) and answer sums fast....
2 views
24 Jan 2026
Read n. Define function step(x) that returns x//2 if x even else 3*x+1. Starting from n, keep applying step until 1. Output number of steps....
2 views
24 Jan 2026
Read sorted array of n integers and target x, write function bsearch(arr,x) returning index (0-based) or -1. Output result....
2 views
24 Jan 2026
Read m n. Write function ways(m,n) that returns number of paths from (0,0) to (m-1,n-1) moving only right or down....