Skip to content

Algorithms Lab

CSE · Quiz · Fall 26

Section 70_M · Batch 70 · shared by Shaker Abdullah

This browser can’t show the PDF here

Open it in a new tab or download it instead.

Read the questions as text

Read off the PDF by AI, so it may have mistakes. The PDF is the original.

Lab Evaluation 1: Problem 1 — The Damaged Number Plate A vehicle registration system stores numeric identification codes. During a system migration, the verification module requires the digits of each code to be read backward. Given an integer N, reverse its digits. Leading zeros in the reversed result must be removed automatically. Negative inputs must retain their negative sign. Input A single integer N, where -10^9 ≤ N ≤ 10^9. Output Print the reversed integer. Sample Input 30500 Sample Output 503 Problem 2 — The Alien Signal Generator A research station receives a sequence of energy readings from an alien signal generator. The first two readings are known. Each subsequent reading is generated by adding the previous reading to twice the reading before it, then adding the current position. The sequence follows these rules: S_1 = A, S_2 = B S_i = S_{i-1} + 2S_{i-2} + i, i ≥ 3 Given A, B, and N, print the first N readings. Input Three integers A, B, and N, where 1 ≤ A, B ≤ 100 and 2 ≤ N ≤ 20. Output Print the first N terms separated by spaces. Sample Input 1 2 6 Sample Output 1 2 7 15 30 59 Problem 3 — The Most Popular Product An online store records the product IDs purchased during a promotional event. The manager wants to find the product ID purchased the greatest number of times. If multiple product IDs have the same maximum frequency, select the one that appeared earliest in the original input sequence. Given the list of product IDs, determine the winning product ID. Input The first line contains N, where 1 ≤ N ≤ 1000. The second line contains N integers, each between 1 and 100. Output Print the winning product ID. Sample Input 7 8 4 6 4 8 6 9 Sample Output 8 Lab Evaluation 1: Problem 1 — The Security Checkpoint A security checkpoint assigns a numeric access code to every visitor. Before the code is stored, the system must reverse its digits to generate a verification code. Given an integer N, print its digits in reverse order. If the reversed number contains leading zeros in its original representation, those zeros are not printed. If the input is a negative integer, preserve the negative sign. Input A single integer N, where -10^9 ≤ N ≤ 10^9. Output Print the reversed integer. Sample Input -12040 Sample Output -4021 Problem 2 — The Mutating Robot A robot starts with two energy values, A and B. At every next step, its new energy is calculated by adding the previous two energy values and then adding the current step number. The sequence is defined as: T_1 = A, T_2 = B T_i = T_{i-1} + T_{i-2} + i, i ≥ 3 Given A, B, and N, print the first N energy values. Input Three integers A, B, and N, where 1 ≤ A, B ≤ 100 and 2 ≤ N ≤ 20. Output Print the first N terms separated by spaces. Sample Input 2 3 6 Sample Output 2 3 8 15 28 48 Problem 3 — The Suspicious Ticket Counter At a technology fair, every visitor receives a ticket number. The organizers want to identify the first ticket number, scanning from left to right, that occurs exactly once in the entire list. Given N ticket numbers, print the first number whose total frequency is exactly one. If no such number exists, print NONE. Input The first line contains N, where 1 ≤ N ≤ 1000. The second line contains N integers, each between -100 and 100. Output Print the first non-repeating number, or NONE. Sample Input 8 4 2 7 2 4 9 7 5 Sample Output 9 Lab Evaluation 1 — Set B Question 1: The Odd-Even Reordering Machine Problem Statement A data processing machine receives an array of N integers. It rearranges the elements according to their original positions. The machine follows these rules: 1. First, print all elements originally at odd positions, preserving their relative order. 2. Then, print all elements originally at even positions, preserving their relative order. 3. Positions are counted starting from 1. Your task is to print the resulting array. Input Format ● The first line contains an integer N, where 1 ≤ N ≤ 1000. ● The second line contains N integers. Output Format Print the reordered array. Sample Input 1 7 11 22 33 44 55 66 77 Sample Output 1 11 33 55 77 22 44 66 Sample Input 2 5 8 3 9 2 7 Sample Output 2 8 9 7 3 2 Special Conditions ● Preserve the original relative order within each group. ● Group elements by their original positions, not by whether their values are odd or even. ● The array may contain duplicates and negative integers. Question 2: The Even-Power Signature Problem Statement A positive integer is called an Even-Power Signature Number if the sum of the squares of its even digits and the cubes of its odd digits equals the original number. Rules: ● Each even digit contributes its square. ● Each odd digit contributes its cube. ● The sum of all contributions must equal N. For example, for N = 123: 1^3 + 2^2 + 3^3 = 1 + 4 + 27 = 32 Since 32 ≠ 123, it is not an Even-Power Signature Number. Input Format A single positive integer N, where 1 ≤ N ≤ 10^6. Output Format Print YES if the number satisfies the condition; otherwise, print NO. Sample Input 1 123 Sample Output 1 NO Sample Input 2 153 Sample Output 2 YES Question 3: The Uniqueness Inspector Problem Statement A data analyst receives a sequence of N non-negative integers. The analyst wants to count how many elements satisfy both conditions: ● The value appears exactly once in the sequence. ● The value is strictly greater than the arithmetic mean of all N elements. Your task is to count the number of eligible elements. Input Format ● The first line contains an integer N, where 1 ≤ N ≤ 1000. ● The second line contains N integers, where 0 ≤ A_i ≤ 10^6. Output Format Print one integer: the number of eligible elements. Sample Input 1 6 2 4 4 8 10 12 Sample Output 1 3 Explanation The sum is 40, so the average is approximately 6.67. The values occurring exactly once are 2, 8, 10, and 12. Of these, 8, 10, and 12 are strictly greater than the average. Therefore, the answer is 3. Sample Input 2 5 5 5 5 5 5 Sample Output 2 0 Lab Evaluation 1 — Set A Question 1: The Circular Shift Challenge Problem Statement A robot stores N integers in an array. It performs a special operation called a Circular Right Shift. During one shift, every element moves one position to the right, and the last element moves to the first position. The robot performs this operation exactly K times. Your task is to print the final array. Input Format ● The first line contains two integers N and K, where 1 ≤ N ≤ 1000 and 0 ≤ K ≤ 10^9. ● The second line contains N integers. Output Format Print the array after performing K circular right shifts. Sample Input 5 2 10 20 30 40 50 Sample Output 40 50 10 20 30 Special Conditions ● If K = 0, the array remains unchanged. ● K can be much larger than N. ● Avoid unnecessary repeated shifts. Question 2: The Weighted Power Number Problem Statement A positive integer is called a Weighted Power Number if the sum of each digit raised to the power of its position from the right equals the original number. For example, the rightmost digit has position 1, the next digit has position 2, and so on. For a number with digits d_1, d_2, ..., d_k, where d_1 is the rightmost digit, the condition is: N = ∑_{i=1}^k d_i^i Given an integer N, determine whether it is a Weighted Power Number. Input Format A single positive integer N, where 1 ≤ N ≤ 10^6. Output Format Print YES if the number satisfies the condition; otherwise, print NO. Sample Input 1 1 Sample Output 1 YES Sample Input 2 89 Sample Output 2 NO Question 3: The Dominant Digit Challenge Problem Statement A security system analyzes N non-negative integers and identifies the Dominant Digit across all their decimal representations. A digit is dominant if it occurs more times than any other digit. If multiple digits have the same highest frequency, select the smallest digit. Every occurrence counts, including repeated digits within the same number. Input Format ● The first line contains an integer N, where 1 ≤ N ≤ 100. ● The second line contains N non-negative integers, each at most 10^9. Output Format Print the dominant digit and its total frequency. Sample Input 4 122 232 901 222 Sample Output 2 7 Explanation The digit 2 appears seven times, more than any other digit.