0% found this document useful (0 votes)
12 views44 pages

Level 3

The document outlines various programming tasks related to data analysis, including counting duplicates in arrays, calculating frequency of elements, rotating arrays, finding temperature extremes, identifying pairs of menu items that sum to a specified amount, and optimizing transaction status arrays. Each task is accompanied by constraints and multiple test cases with expected outputs. The document serves as a comprehensive guide for developing solutions to these data processing challenges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views44 pages

Level 3

The document outlines various programming tasks related to data analysis, including counting duplicates in arrays, calculating frequency of elements, rotating arrays, finding temperature extremes, identifying pairs of menu items that sum to a specified amount, and optimizing transaction status arrays. Each task is accompanied by constraints and multiple test cases with expected outputs. The document serves as a comprehensive guide for developing solutions to these data processing challenges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LEVEL 3

1. Imagine you're a data analyst, delving into a vast array of numerical data, meticulously
unraveling insights hidden within its intricate patterns. Your mission is to count the total
number of duplicate elements lurking within this dataset of integers. As you embark on
this journey, each integer represents a unique piece of information crucial to
understanding trends and anomalies. Your goal is to develop a program that not only
identifies but also quantifies the occurrence of duplicate entries, guiding decision-makers
towards informed strategies.

Let's denote the following variable:


A → Array of integers
→ Set of all integers
∣A∣ → Cardinality of array A, indicating the number of elements in A
Count(A) → Total number of duplicate elements in array A.

Constraints:

1{𝐴 ​𝑎𝑝𝑝𝑒𝑎𝑟𝑠 𝑚𝑜𝑟𝑒 𝑡ℎ𝑎𝑛 𝑜𝑛𝑐𝑒 𝑖𝑛 𝐴}​ is the indicator function that evaluates to 1 if the
𝑖

element Ai​appears more than once in A, and 0 otherwise.

Test Case 1:
Input:
Array size: 1
Array value: 1
Expected Output: 0
Explanation: The array has only one element, so there are no duplicates.
Test Case 2:
Input:
Array size: 5
Array value: 1 2 3 4 5
Expected Output: 0
Explanation: All elements are unique, so no duplicates are found.
Test Case 3:
Input:
Array size: 5
Array value: 2 2 2 2 2
Expected Output: 4
Explanation: The number 2 appears 5 times, resulting in 4 duplicates.
Test Case 4:
Input:
Array size: 7
Array value: 1 2 3 2 4 5 1
Expected Output: 2
Explanation: There is 1 duplicate of the number 1 and 1 duplicate of the number 2,
totaling 2 duplicates.
Test Case 5:
Input:
Array size: 7
Array value: 1 2 3 10000 1 2 3
Expected Output: 3
Explanation: The numbers 1, 2, and 3 are duplicated once each.
Test Case 6:
Input:
Array size: 5
Array value: -1 -2 -3 -1 -2
Expected Output: 2
Explanation: There is 1 duplicate of -1 and 1 duplicate of -2, totaling 2 duplicates.
Test Case 7:
Input:
Array size: 5
Array value: 0 0 0 0 0
Expected Output: 4
Explanation: There is 1 duplicate of 1 and 1 duplicate of -1, totaling 2 duplicates.
Test Case 8:
Input:
Array size: 7
Array value: Z E N I T S U
Expected Output:
Invalid input
Explanation: Input should be an integer value.
Test Case 9:
Input:
Array size: 0
Expected Output:
Invalid input
Test Case 10:
Input:
Array size: 5
Array value: 1 2 m 1 2
Expected Output:
Invalid input
2. A data scientist is entrusted with analyzing a diverse dataset comprising arrays of
integers. Develop a robust program capable of meticulously counting the frequency of
each unique element within these arrays, offering a clear snapshot of their distribution
and importance. Each integer within the array represents a unique data point pivotal to
understanding patterns and trends. Craft a solution that not only identifies but also
quantifies the occurrence of each element, providing stakeholders with actionable
insights for informed decision-making.
Let's denote the following variable:
𝐴 = [𝑎1, 𝑎2, ... , 𝑎𝑛] → Array of n integers, where each 𝑎𝑖ϵ𝑍 (integers).
Frequency(𝑎𝑖) → Frequency of the integer 𝑎𝑖 in the array A.
Constraints:

Test Case 1:
Input:
Array size: 5
Array value: 1 2 3 4 5
Expected Output:
1: 1
2: 1
3: 1
4: 1
5: 1
Test Case 2:
Input:
Array size: 6
Array value: 1 1 2 2 3 3
Expected Output:
1: 2
2: 2
3: 2
Test Case 3:
Input:
Array size: 0
Expected Output:
Invalid input
Test Case 4:
Input:
Array size: 1
Array value: 1
Expected Output:
1: 1
Test Case 5:
Input:
Array size: 15
Array value: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Expected Output:
1: 3
2: 3
3: 3
4: 3
5: 3
Test Case 6:
Input:
Array size: 8
Array value: -1 2 -1 3 4 -1 4 5
Expected Output:
-1: 3
2: 1
3: 1
4: 2
5: 1
Test Case 7:
Input:
Array size: 3
Array value: 0 0 0
Expected Output:
0: 3
Test Case 8:
Input:
Array size: 9
Array value: 1 2 @
Expected Output:
Invalid input
Test Case 9:
Input:
Array size: 6
Array value: M I K A S A
Expected Output:
Invalid input
3. Develop a scheduling system for a manufacturing plant where production lines need to
be rotated periodically to evenly distribute wear and tear on machinery. Each production
line is represented by an array of integers, where each integer corresponds to a specific
machine or task. The system requires the ability to rotate these arrays by a specified
number of positions to ensure optimal operational efficiency and longevity of equipment.

Let's denote the following variable:

A=[A[0], A[1], … , A[n−1]] → Array of integers

n → Length of the array A

k → Number of positions by which the array A should be rotated

Constraints:
● A → Positive and negative integers
● n>0
● 0<=k<n

Test Case 1:
Input:
Array size: 1
Array value: 1
Rotation value: 5
Expected Output: [1]
Test Case 2:
Input:
Array size: 5
Array value: 1 2 3 4 5
Rotation value: 0
Expected Output: [1, 2, 3, 4, 5]
Test Case 3:
Input:
Array size: 10
Array value: 1 2 3 4 5 6 7 8 9 10
Rotation value: 9
Expected Output: [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]
Test Case 4:
Input:
Array size: 5
Array value: 1 2 3 4 5
Rotation value: 5
Expected Output: [1, 2, 3, 4, 5]
Test Case 5:
Input:
Array size: 5
Array value: -3 0 5 -7 2
Rotation value: 3
Expected Output: [5, -7, 2, -3, 0]
Test Case 6:
Input:
Array size: 6
Array value: 10 20 30 40 50 60
Rotation value: -4
Expected Output: Invalid rotation
Test Case 7:
Input:
Array size: 5
Array value: 5 5 5 5 5
Rotation value: 2
Expected Output: [5, 5, 5, 5, 5]
Test Case 8:
Input:
Array size: 5
Array value: 1 -2 3 -4 5
Rotation value: 1
Expected Output: [5, 1, -2, 3, -4]
Test Case 9:
Array size: -6
Expected Output:
Invalid input
Test Case 10:
Input:
Array size: 12
Array value: O B I T O _ U C H I H A
Expected Output:
Invalid input.
4. Imagine you're a climatologist analyzing temperature data recorded over a year to
understand climate patterns. Your dataset consists of daily temperature readings, and you
need to identify the highest and lowest temperatures recorded throughout the year. This
analysis helps in studying extreme weather conditions, planning agricultural activities,
and preparing for climate-related disasters.
Let T → real numbers representing temperatures
Constraints:
−50 < = 𝑇𝑖​<= 50
Maximum Array Size → 365 [Temperature Record of each day in a year]
Test Case 1:
Input:
Array size: 1
Array value: -50
Expected Output:
Minimum: -50
Maximum: -50
Test Case 2:
Input:
Array size: 1
Array value: 50
Expected Output:
Minimum: 50
Maximum: 50
Test Case 3:
Input:
Array size: 6
Array value: -30 25 -15 45 0 20
Expected Output:
Minimum: -30
Maximum: 45
Test Case 4:
Input:
Array size: 5
Array value: 10 10 10 10 10
Expected Output:
Minimum: 10
Maximum: 10
Test Case 5:
Input:
Array size: 9
Array value: -40 -30 -20 -10 0 10 20 30 40
Expected Output:
Minimum: -40
Maximum: 40
Test Case 6:
Input:
Array size: 9
Array value: 40 30 20 10 0 -10 -20 -30 -40
Expected Output:
Minimum: -40
Maximum: 40
Test Case 7:
Input:
Array size: 13
Array value: I T A C H I _ U C H I H A
Expected Output:
Invalid input.
5. In a busy restaurant, the cashier needs a program to quickly identify pairs of menu
items that customers frequently order together. Each menu item is represented by an
integer, and the cashier wants to find any pair of items that sum up to a specified total bill
amount. Write a program in C that efficiently finds and displays any pair of menu items
from an array that together sum up to the total bill amount requested by the customer.

Let's denote the following variable:


A → Array of integers representing menu items
n → Length of the array A
Sum → Specified total bill amount that we want to find pairs for.

Constraints:
● n>0
● Sum = A[i] + A[j] where 0<=i<j<n
● There must exist at least one pair of indices (i,j) satisfying the condition
A[i]+A[j]=Sum.
● If no such pair exists, the program should indicate that no pairs are found.

Test Case 1:
Input:
Array size: 5
Array value: 2 4 6 8 10
Sum= 14
Expected Output:
Pairs found: (4, 10) (6, 8)
Test Case 2:
Input:
Array size: 5
Array value: 2 -2 3 4 5
Sum = 0
Expected Output:
Pairs found: (2, -2)
Test Case 3:
Input:
Array size: 6
Array value: 1 2 3 4 5 6
Sum = 7
Expected Output:
Pairs found: (1, 6) (2, 5) (3, 4)
Test Case 4:
Input:
Array size: 5
Array value: 1 2 3 4 5
Sum = 12
Expected Output:
No pairs found
Test Case 5:
Input:
Array size: 5
Array value: 3 3 3 3 3
Sum = 6
Expected Output:
Pairs found: (3, 3) (3, 3) (3, 3) (3, 3) (3, 3) (3, 3) (3, 3) (3, 3) (3, 3) (3, 3)
Test Case 6:
Input: n = -6
Array size: -6
Expected Output:
Invalid input
Test Case 7:
Input:
Array size: 5
Array value: -2 5 7 -3 6
Sum = -5
Expected Output:
Pairs found: (-2, -3)
Test Case 8:
Input:
Array size: 11
Array value: E R E N _ Y E A G E R
Expected Output:
Invalid input.
Test Case 9:
Input:
Array size: 5
Array value: -1 0 1 2 3
Sum = -1
Expected Output:
Pairs found: (-1, 0)
6. Develop a backend system for a financial institution that processes a large volume of
transactions daily. Each transaction might have associated metadata and status indicators
stored in an array. For example, consider an array where each element represents the
status of a transaction:

● Non-zero values could represent different statuses like "pending", "processed",


"failed", etc.
● Zero values might indicate transactions that are still awaiting processing or have
been marked as canceled.

Optimize the arrangement of elements in an integer array satisfying the below rules:-
● Move all zeros in the array to the end while keeping the order of non-zero
elements unchanged.
● This operation must be performed in-place without allocating extra memory.

Let A be the array of size ‘n’:


A=[a1,a2,…,an]
After moving all zeros to the end while maintaining the order of non-zero
elements:

Constraints:
● 1 <= [Link] <= 104
● -2^31 <= A[i] <= 2^31 - 1

Test Case 1:
Input:
Enter size of array : 4
Enter the elements of array : 0 0 0 0
Output: [0, 0, 0, 0]
Test Case 2:
Input:
Enter size of array : 4
Enter the elements of array : 1 2 3 4
Output: [1, 2, 3, 4]
Test Case 3:
Input:
Enter size of array : 5
Enter the elements of array : 0 0 1 2 3
Output: [1, 2, 3, 0, 0]
Test Case 4:
Input:
Enter size of array : 5
Enter the elements of array : 1 2 3 0 0
Output: [1, 2, 3, 0, 0]
Test Case 5:
Input:
Enter size of array : 5
Enter the elements of array : 1 0 2 0 3
Output: [1, 2, 3, 0, 0]
Test Case 6:
Input:
Enter size of array : 1
Enter the elements of array : 0
Output: [0]
Test Case 7:
Input:
Enter size of array : 1
Enter the elements of array : 1
Output: [1]
Test Case 8:
Input:
Enter size of array : 5
Enter the elements of array : 0 -1 -2 0 -3
Output: [-1, -2, -3, 0, 0]
Test Case 9:
Input:
Enter size of array : 10
Enter the elements of array : 1 2 0 3 0 4 0 5 0 6
Output: [1, 2, 3, 4, 5, 6, 0, 0, 0, 0]
Test Case 10:
Input:
Enter size of array : 10
Enter the elements of array : 0 7 0 7 0 7 0 7 0 7
Output: [7, 7, 7, 7, 7, 0, 0, 0, 0, 0]
7. In a busy restaurant, the reservation system maintains a list of upcoming bookings
represented by an array. Each element in the array represents a reservation, typically
containing details such as reservation ID and deleting elements at specified positions
allows the restaurant to manage cancellations or changes efficiently.

Let's denote the following variable:


A → Array of integers representing upcoming bookings where each element
corresponds to a reservation ID
n → Length of the array A
pos → Specified position in the array A where deletion is required

Constraints:
● n>0
● 0<=pos<n

Test Case 1:
n=1
A = 101
pos = 0
Expected Output: Updated reservations: []
Test Case 2:
n=3
A = 101 102 103
pos = 1
Expected Output: Updated reservations: [101, 103]
Test Case 3:
n=5
A = 101 102 103 104 105
pos = 2
Expected Output: Updated reservations: [101, 102, 104, 105]
Test Case 4:
n=5
A = 101 102 103 104 105
pos = 0
Expected Output: Updated reservations: [102, 103, 104, 105]
Test Case 5:
n=5
A = 101 102 ‘A’
pos = 0
Expected Output: Invalid input
Test Case 6:
n=5
A = 101 102 103 104 105
pos = -3
Expected Output: Invalid position to delete
Test Case 7:
n = -5
Expected Output: Invalid array size
8. Suppose a user searches for "laptops" on an e-commerce platform. The platform
retrieves sorted lists of laptops based on price and relevance from its database. The
platform merges these sorted lists into a single sorted array, considering factors like price
and relevance, to present a comprehensive and user-friendly list of laptops.

Let's denote the following variable:

mrg = m+n → length of array arr1 and arr2

Constraints:
m>0
n>0

Test Case 1:
Enter the size of arr1 : 1
Enter the elements of arr1 : 1000
Enter the size of arr2 : 2
Enter the elements of arr2 : 500 1500
Expected output = [500, 1000, 1500]
Test Case 2:
Enter the size of arr1 : 3
Enter the elements of arr1 : 200 400 600
Enter the size of arr2 : 3
Enter the elements of arr2 : 300 500 700
Expected output = [200, 300, 400, 500, 600, 700]
Test Case 3:
Enter the size of arr1 : 3
Enter the elements of arr1 : 100 200 300
Enter the size of arr2 : 2
Enter the elements of arr2 : 150 250
Expected output = [100, 150, 200, 250, 300]
Test Case 4:
Enter the size of arr1 : 4
Enter the elements of arr1 : 50 150 -250 350
Enter the size of arr2 : 3
Enter the elements of arr2 : 100 200 300
Expected output = [-250, 50, 100, 150, 200, 300, 350]
Test Case 5:
Enter the size of arr1 : 1
Enter the elements of arr1 : 100
Enter the size of arr2 : 1
Enter the elements of arr2 : 200
Expected output = [100, 200]
Test Case 6:
Enter the size of arr1 : 3
Enter the elements of arr1 : 200 400 600
Enter the size of arr2 : 0
Enter the elements of arr2 :
Expected output = [200, 400, 600]
Test Case 7:
Enter the size of arr1 : 0
Enter the elements of arr1 :
Enter the size of arr2 : 3
Enter the elements of arr2 : 100 200 300
Expected output=[100, 200, 300]
Test Case 8:
Enter the size of arr1 : 0
Enter the elements of arr1 :
Enter the size of arr2 : 0
Enter the elements of arr2 :
Expected output=[]
9. You are developing a utility for a data analysis application where you need to compute
the product of all elements in an array except the current element. This will be used for
financial calculations where individual impact assessments are required. Your task is to
write a program that, given an integer array nums, returns an array answer such that
answer[i] is equal to the product of all elements in nums except nums[i].

Let's denote the following variable:

n → Size of the array


i → Index of the array

Constraints

n>0
0<=i<n-1

Example 1:
Input: nums = [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Explanation:
answer[0] = 2 * 3 * 4 = 24
answer[1] = 1 * 3 * 4 = 12
answer[2] = 1 * 2 * 4 = 8
answer[3] = 1 * 2 * 3 = 6
Example 2:
Input: nums = [-1, 1, 0, -3, 3]
Output: [0, 0, 9, 0, 0]
Explanation:
answer[0] = 1 * 0 * -3 * 3 = 0
answer[1] = -1 * 0 * -3 * 3 = 0
answer[2] = -1 * 1 * -3 * 3 = 9
answer[3] = -1 * 1 * 0 * 3 = 0
Test Case 1: Basic Case
Input:
Enter the size of array : 4
Enter the elements of array : 1 2 3 4
Expected output: [24, 12, 8, 6]
Test Case 2: Zero in Array
Input:
Enter the size of array : 5
Enter the elements of array : -1 1 0 -3 3
Expected Output: [0, 0, 9, 0, 0]
Test Case 3: All Positive Numbers
Input:
Enter the size of array : 4
Enter the elements of array : 2 3 4 5
Expected Output: [60, 40, 30, 24]
Test Case 4: All Negative Numbers
Input:
Enter the size of array : 4
Enter the elements of array : -2 -3 -4 -5
Expected Output: [-60, -40, -30, -24]
Test Case 5: Single Element
Input:
Enter the size of array : 1
Enter the elements of array : 10
Expected Output: [1] # Because there are no other elements to multiply with
Test Case 6: Two Elements
Input:
Enter the size of array : 2
Enter the elements of array : 3 5
Expected Output: [5, 3]
Test Case 7: Mixed Positive and Negative
Input:
Enter the size of array : 4
Enter the elements of array : -2 4 -6 3
Expected Output: [-72, 36, -24, 48]
Test Case 8: Invalid Input
Input:
Enter the size of array : 3
Enter the elements of array : 1000 20.00 3000
Expected Output: Invalid array elements
Test Case 9: Array with Duplicates
Input:
Enter the size of array : 4
Enter the elements of array : 2 2 3 4
Expected Output: [24, 24, 16, 12]
Test Case 10: Array with Negative Zero and Positive Zero
Input: nums = [0, -0, 2, -3]
Enter the size of array : 4
Enter the elements of array : 0 -0 2 -3
Expected Output: [0, 0, 0, 0]
10. Develop a financial application that needs to analyze patterns in transaction logs.
Each transaction is represented by an integer value in an array, where the same
transaction might appear multiple times. Your goal is to determine the maximum time gap
between two occurrences of the same transaction to assess how frequent or infrequent
certain transactions are over time. For a given integer array transaction, the program
should return the maximum distance between any two occurrences of the same
transaction.

Let's denote the following variable:

transaction = [𝑡1, 𝑡2, 𝑡3, ... , 𝑡𝑛] → An array representing transaction identifiers

n → Number of elements in the array transaction

Constraints:

● 𝑡𝑖 ϵ 𝑡𝑟𝑎𝑛𝑠𝑎𝑐𝑡𝑖𝑜𝑛 for i = 1, 2, … , n


● [Link] == n
● 0 <= n <=100

Example 1:
Input: transaction = [1, 2, 1, 4, 1]
Expected Output: 4
Explanation: Maximum gap between occurrences of transaction '1' is between index 4
and 0, which is 4.

Example 2:
Input: transaction = [2, 1, 3, 1, 4, 3, 2]
Expected Output: 6
Explanation: Maximum gap between occurrences of transaction '2' is between index 6
and 0 which is 6, transaction ‘1’ is between 1 and 3 which is 2, transaction ‘3’ is between
2 and 5 which is 3. The maximum gap among transactions ‘2’, ‘1’ and ‘3’ is transaction
‘2’ i.e. 6. So, output will be 6
Test Case 1: Basic Case
Input:
Enter number of transactions: 5
Enter the transactions: 1 2 1 4 1
Expected Output:
Maximum time gap: 4
Test Case 2: All Same Transaction
Input:
Enter number of transactions: 5
Enter the transactions: 5 5 5 5 5
Expected Output:
Maximum time gap: 4
Test Case 3: Multiple Occurrences
Input:
Enter number of transactions: 7
Enter the transactions: 2 1 3 1 4 3 2
Expected Output
Maximum time gap: 6

Test Case 4: Single Element


Input:
Enter number of transactions: 1
Enter the transactions: 10
Expected Output
Maximum time gap: 0

Test Case 5: No Repeated Transactions


Input:
Enter number of transactions: 5
Enter the transactions: 1 2 3 4 5
Expected Output
Maximum time gap: 0
Test Case 6: Negative Numbers
Input:
Enter number of transactions: 5
Enter the transactions: -2 1 -2 4 -2
Expected Output
Maximum time gap: 4

Test Case 7: Mixed Positive and Negative


Input:
Enter number of transactions: 7
Enter the transactions: 1 -3 1 4 -3 -3 2
Expected Output
Maximum time gap: 4

Test Case 8: Invalid Input


Input:
Enter number of transactions: 4
Enter the transactions: 10000 x 10000 20000
Expected Output
Segmentation fault

Test Case 9: Empty Array


Input:
Enter number of transactions: 0
Expected Output
Maximum time gap 0

Test Case 10: Zero Transaction


Input:
Enter number of transactions: 6
Enter the transactions: 0 2 0 4 0 0
Expected Output
Maximum time gap: 5
11. Imagine you're analyzing a dataset of product prices to understand how each price
compares to others in the list. For each price, you need to determine how many prices are
less than it. This will help in identifying the market position of each product and
understanding pricing trends. For a given integer array of prices, the program should
return an array where each element represents how many prices in the original array are
smaller than the corresponding price.

Let's denote the following variable:

n → Size of the integer array

Constrains:


● 0 <= n <= 100
● [Link] == n
● s_count.length == n

Example 1:
Input: prices = [8, 1, 2, 10]
Expected Output: [2, 0, 1, 3]
Explanation:
- 8 has 2 prices smaller than it (1, 2).
- 1 has 0 prices smaller than it.
- 2 has 1 price smaller than it (1).
- 10 has 3 prices smaller than it (8, 1, 2).

Example 2:
Input: prices = [-1, 2, -3, 4, -5]
Expected Output: [2, 3, 1, 4, 0]
Explanation:
- (-1) has 2 prices smaller than it (-3, -5).
- 2 has 3 prices smaller than it (-1, -3, -5).
- (-3) has 1 price smaller than it (-5)
- 4 has 4 prices smaller than it (-1, 2, -3, -5).
- (-5) has 0 price smaller than it.

Test Case 1: Basic Case


Input:
Enter the number of prices: 4
Enter 4 prices:
8 1 2 10
Output: 2 0 1 3

Test Case 2: All Same Prices


Input:
Enter the number of prices: 5
Enter 5 prices:
55555
Output: 0 0 0 0 0

Test Case 3: Decreasing Order


Input:
Enter the number of prices: 5
Enter 5 prices:
10 8 5 3 1
Output: 4 3 2 1 0

Test Case 4: Increasing Order


Input:
Enter the number of prices: 5
Enter 5 prices:
1 3 5 8 10
Output: 0 1 2 3 4

Test Case 5: Empty Array


Input:
Enter the number of prices: 0
Output: 0
Test Case 6: Single Element
Input:
Enter the number of prices: 1
Enter 1 prices:
7
Output: 0

Test Case 7: Mixed Positive and Negative


Input
Enter the number of prices: 5
Enter 5 prices:
-1 2 -3 4 -5
Output: 2 3 1 4 0

Test Case 8: Zero Prices


Input:
Enter the number of prices: 5
Enter 5 prices:
00000
Output: 0 0 0 0 0

Test Case 9: Invalid Input (Use atoi() Function)


Input:
Enter the number of prices: 4
Enter 4 prices:
100 A 200 300
Invalid array elements

Test Case 10: Max Size


Input:
Enter the number of prices: 15
Enter 15 prices:
5 4 3 2 1 6 7 8 9 10 11 12 13 14 15
Output: 4 3 2 1 0 5 6 7 8 9 10 11 12 13 14
12. You are tasked with finding all unique combinations of product prices that sum up to
a given budget. Each price can only be used once in a combination. The goal is to
identify all possible combinations that meet the budget constraint, ensuring that no
duplicate combinations are included in the results.

Let's denote the following variable:


𝑝𝑟𝑖𝑐𝑒𝑠 = [𝑝1, 𝑝2, 𝑝3, ... , 𝑝𝑛] → Array of integers representing product price

B → Target sum

Constraints:

Test Case 1: Basic Case


Enter the number of prices: 4
Enter 4 prices:
2357
Enter the budget : 8
Expected Output:
[3, 5]
Test Case 2: Multiple Combinations
Input:
Enter the number of prices: 5
Enter 5 prices:
12345
Enter the budget: 5
Expected Output:
[2, 3]
[1, 4]
[5]
Test Case 3: No Valid Combinations
Input:
Enter the number of prices: 4
Enter 4 prices:
2468
Enter the budget : 7
Expected Output:
No valid combinations found
Test Case 4: All Prices Same
Input:
Enter the number of prices: 4
Enter 4 prices:
3333
Enter the budget : 3
Expected Output:
[3]
Test Case 5: Invalid Input
Input:
Enter the number of prices: 5
Enter 5 prices:
10 2.23 30 40 50
Expected Output:
Invalid Input
Test Case 6: Empty Array
Input:
Enter the number of prices: 0
Expected Output:
Empty Array

Test Case 7: Single Element Array


Input:
Enter the number of prices: 1
Enter 1 prices:
7
Enter the budget : 7
Expected Output:
[7]
Test Case 8: Negative Prices
Input:
Enter the number of prices: 4
Enter 4 prices:
-2 3 -5 8
Enter the budget: 1
Expected Output:
[-2, 3]
[-5, -2, 8]

Test Case 9: Zero Budget


Input:
Enter the number of prices: 4
Enter 4 prices:
1234
Enter the budget: 0
Expected Output:
Zero Budget

Test Case 10: Maximum Size with Large Budget


Input:
Enter the number of prices: 10
Enter 10 prices:
1 2 3 4 5 6 7 8 9 10
Enter the budget: 15
Expected Output:
[1, 2, 3, 4, 5]
[2, 3, 4, 6]
[1, 3, 5, 6]
[4, 5, 6]
[1, 3, 4, 7]
[1, 2, 5, 7]
[3, 5, 7]
[2, 6, 7]
[1, 2, 4, 8]
[3, 4, 8]
[2, 5, 8]
[1, 6, 8]
[7, 8]
[1, 2, 3, 9]
[2, 4, 9]
[1, 5, 9]
[6, 9]
[2, 3, 10]
[1, 4, 10]
[5, 10]
13. You are working on a data analysis project for a financial services company. The
company has a large dataset of stock prices, and they want to analyze the behavior of the
stock market. One of the analyses they want to perform is to count the number of smaller
elements on the right side of each element in the stock price array. This information can
be useful for identifying trends and patterns in the stock market. Your task is to write a
program that takes an array of stock prices as input and returns an array that contains the
count of smaller elements on the right side of each element in the input array.

Let's denote the following variable:


𝑝𝑟𝑖𝑐𝑒𝑠 = [𝑝1, 𝑝2, 𝑝3, ... , 𝑝𝑛] → Array of stock prices

count_smaller[i] → Number of elements to the right of 𝑝𝑖​that are smaller than 𝑝𝑖


n → Number of elements in stock price array

Constraints:

● 0<=i<n
● j>i
● 𝑝𝑗 < 𝑝𝑖

Example 1:
Input: prices = [1000, 500, 750, 2000, 250]
Expected Output: [3, 1, 1, 1, 0]
Explanation:
- For price 1000: There are 3 smaller elements (500, 750, 250) to its right.
- For price 500: There is 1 smaller element (250) to its right.
- For price 750: There are 1 smaller element (250) to its right.
- For price 2000: There are 1 smaller element (250) to its right.
- For price 250: There are 0 smaller elements to its right.

Example 2:
Input: prices = [3, -1, 2, 0, -2]
Expected Output: [4, 1, 2, 1, 0]
Explanation:
- For price 3: There are 4 smaller elements (-1, 2, 0, -2) to its right.
- For price -1: There is 1 smaller element (-2) to its right.
- For price 2: There are 2 smaller elements (0, -2) to its right.
- For price 0: There is 1 smaller element (-2) to its right.
- For price -2: There are 0 smaller elements to its right.

Test Case 1: Basic Case


Input: prices = [3, 1, 2, 4]
Expected Output: [2, 0, 0, 0]
Test Case 2: All Prices Same
Input: prices = [5, 5, 5, 5]
Expected Output: [0, 0, 0, 0]
Test Case 3: Descending Order
Input: prices = [5, 4, 3, 2, 1]
Expected Output: [4, 3, 2, 1, 0]
Test Case 4: Ascending Order
Input: prices = [1, 2, 3, 4, 5]
Expected Output: [0, 0, 0, 0, 0]
Test Case 5: Single Element
Input: prices = [7]
Expected Output: [0]
Test Case 6: Empty Array
Input: prices = []
Expected Output: []
Test Case 7: Negative Prices
Input: prices = [-1, -5, -3, -2]
Expected Output: [3, 0, 0, 0]
Test Case 8: Mixed Positive and Negative Prices
Input: prices = [3, -1, 2, 0, -2]
Expected Output: [4, 1, 2, 1, 0]
Test Case 9: Large Numbers
Input: prices = [1000, 500, 750, 2000, 250]
Expected Output: [3, 1, 1, 1, 0]
Test Case 10: Random Prices
Input: prices = [6, 1, 5, 2, 4, 3]
Expected Output: [5, 0, 3, 0, 1, 0]
14. Suppose you have a dataset where values are stored in a sorted integer array, and each
element represents a unique data point or measurement. Removing duplicates from this
array ensures that each unique value appears only once. This process is crucial in data
preprocessing steps before performing statistical analysis, generating reports, or feeding
data into machine learning algorithms. This efficiency is beneficial when handling large
datasets to minimize memory usage and optimize performance.

Let's denote the following variable:


𝑛𝑢𝑚𝑠 = [𝑥1, 𝑥2, 𝑥3, ... , 𝑥𝑛] → sorted integer array
n → Size of the sorted integer array

Constraints:
5
● 1<=[Link]<=10
● -100<=nums[i]<=100
● nums is sorted in non-decreasing order
● n>0

Test Case 1: Basic Case - No Duplicates


Input: nums = [1, 2, 3, 4, 5]
Expected Output: [1, 2, 3, 4, 5]
Test Case 2: All Elements Same
Input: nums = [1, 1, 1, 1, 1]

Expected Output: [1]


Test Case 3: Mixed Duplicates
Input: nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
Expected Output: [1, 2, 3, 4, 5]
Test Case 4: Negative Numbers
Input: nums = [-3, -2, -2, -1, 0, 0, 1, 2, 3]
Expected Output: [-3, -2, -1, 0, 1, 2, 3]
Test Case 5: Single Element
Input: nums = [5]
Expected Output: [5]
Test Case 6: Mixed Small Array
Input: nums = [-10, -5, 0, 0, 3, 3, 5, 8]
Expected Output: [-10, -5, 0, 3, 5, 8]
Test Case 7: All zeroes
Input: nums = [0, 0, 0]
Expected Output: [0]
Test Case 8: Invalid array elements
Input: nums = [500, 1000, 1500, 1500, 2000]
Expected Output: Invalid array elements
15. In scientific computing and numerical simulations, verifying whether a given matrix
is symmetric or not is crucial for ensuring the accuracy, efficiency, and reliability of
computations. By confirming symmetry, researchers and engineers can confidently apply
specialized algorithms, validate physical models, and derive meaningful insights that
contribute to advancements in scientific knowledge and technological innovation.

Let's denote the following variable:


𝐴 → given matrix of size m*n
m → number of rows in the matrix A
n → number of columns in the matrix A

Constraints:
● The matrix A is symmetric if it satisfies:
𝑇 𝑇
𝐴 = 𝐴 , 𝑤ℎ𝑒𝑟𝑒 𝐴 𝑖𝑠 𝑡ℎ𝑒 𝑡𝑟𝑎𝑛𝑠𝑝𝑜𝑠𝑒 𝑜𝑓 𝐴
● m==n
● 1<m,n<=10
● -100 <= 𝐴𝑖𝑗<=100

Test Case 1: Single row and single column


Enter the number of rows: 1
Enter the number of columns: 1
Enter element : 10
Expected Output: Symmetric
Test Case 2: Square Symmetric Matrix
Enter the number of rows: 2
Enter the number of columns: 2
Enter element : 1
Enter element : 2
Enter element : 2
Enter element : 3
Expected Output: Symmetric
Test Case 3: Rectangular Matrix (m != n)
Enter the number of rows: 2
Enter the number of columns: 3
Enter element : 1
Enter element : 2
Enter element : 3
Enter element : 2
Enter element : 4
Enter element : 5
Expected Output: Not symmetric
Test Case 4: All Elements Same (Square Matrix)
Enter the number of rows: 2
Enter the number of columns: 2
Enter element : 5
Enter element : 5
Enter element : 5
Enter element : 5
Expected Output: Symmetric
Test Case 5: Negative Numbers and Zeroes (Square Matrix):
Enter the number of rows: 2
Enter the number of columns: 2
Enter element : 0
Enter element : -1
Enter element : -1
Enter element : 2
Expected Output: Symmetric
Test Case 6: Identity Matrix (Square Matrix)
Enter the number of rows: 3
Enter the number of columns: 3
Enter element : 1
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 1
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 1
Expected Output: Symmetric
Test Case 7: Rectangular Matrix (m < n)
Enter the number of rows: 3
Enter the number of columns: 2
Enter element : 1
Enter element : 2
Enter element : 3
Enter element : 4
Enter element : 5
Enter element : 6
Expected Output: Not symmetric
Test Case 8: Square Matrix with All Zeroes (m = n = 3)
Enter the number of rows: 3
Enter the number of columns: 3
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 0
Enter element : 0
Expected Output: Symmetric
Test Case 9: Invalid row
Enter the number of rows: -3
Enter the number of columns: 3
Expected Output: Invalid row value
Test Case 10: Invalid column
Enter the number of rows: 4
Enter the number of columns: 0
Expected Output: Invalid column value
16. Consider you are working on a data analysis project for a financial services company.
The company has a large dataset of customer transactions, and they want to analyze the
individual digits that make up the transaction amounts. The data is stored in an array of
positive integers, where each integer represents a transaction amount. However, the
company wants to analyze the individual digits that make up each transaction amount,
rather than just the whole number. Your task is to write a program that takes an array of
positive integers and returns a new array that consists of the digits of each integer in the
original array, separated in the same order they appear in the original array.

Let's denote the following variable:


𝑛𝑢𝑚𝑠 = [𝑥1, 𝑥2, 𝑥3, ... , 𝑥𝑛] → Input array of positive integers
𝑥𝑖 → Each integer in the array nums
𝑑(𝑥𝑖) → Digits of the integer 𝑥𝑖
Constraints:
● ∀𝑖 ϵ {1, 2, 3, ... , 𝑛}, 𝑥𝑖>0
● n>0
5
● 1 <= 𝑥𝑖 < 10

Test Case 1: Simple Case with Single Digit Numbers


nums = [1, 2, 3, 4, 5]
Expected Output: [1, 2, 3, 4, 5]
Test Case 2: Numbers with Multiple Digits
nums = [123, 456, 789]
Expected Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
Test Case 3: Large Numbers within Range
nums = [999, 10000, 54321]
Expected Output: [9, 9, 9, 1, 0, 0, 0, 0, 5, 4, 3, 2, 1]
Test Case 4: Edge Case: Minimum Valid Input Size
nums = [1]
Expected Output: [1]
Test Case 5: Maximum Valid Input Size
nums = [99999, 88888, 77777]
Expected Output: [9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7]
Test Case 6: All Numbers are the Same
nums = [555, 555, 555]
Expected Output: [5, 5, 5, 5, 5, 5, 5, 5, 5]
Test Case 7: Empty array
nums = []
Expected Output: []
Test Case 8: Numbers with Leading Zeros
nums = [101, 500, 90007]
Expected Output: [1, 0, 1, 5, 0, 0, 9, 0, 0, 0, 7]
Test Case 9: All Digits are Zero
nums = [0, 0, 0]
Expected Output: [] #The output is an empty array because there are no digits to extract
from zero.
Test Case 10: Negative Input
nums = [8,- 22, 4, 99]
Expected Output: Invalid input
Extra
17. The ECU receives sensor data from various sources, including temperature sensors,
pressure sensors, and speed sensors. These sensors provide data as binary numbers. The
system uses one’s and two's complement representation for further processing.

Let's denote the following variable:


b → The binary number entered by the user.

Constraints:
+
● 𝑏 ϵ {0, 1}
● b should be a non-empty (i.e., it should contain at least one digit).
● b should have maximum of 8 bits only, if lesser append 0’s in MSB
● Output of one’s and two’s complement will be represented in 8 bits only

Test Case 1:
Input: b=1
Expected One's Complement: 11111110
Expected Two's Complement: 11111111
Test Case 2:
Input: b=0
Expected One's Complement: 11111111
Expected Two's Complement: 00000000
Test Case 3:
Input: b=10
Expected One's Complement: 11111101
Expected Two's Complement: 11111110
Test Case 4:
Input: b=01
Expected One's Complement: 11111110
Expected Two's Complement: 11111111
Test Case 5:
Input: b=110
Expected One's Complement: 11111001
Expected Two's Complement: 11111010
Test Case 6:
Input: b=101
Expected One's Complement: 11111010
Expected Two's Complement: 11111011
Test Case 7:
Input: b=1111
Expected One's Complement: 11110000
Expected Two's Complement: 11110001
Test Case 8:
Input: b=0000
Expected One's Complement: 11111111
Expected Two's Complement: 00000000
Explanation: One's complement of 0000 is 1111, and adding 1 to 1111 gives 0000
(overflow).
Test Case 9:
Input: b=101010
Expected One's Complement: 11010101
Expected Two's Complement: 11010110
Test Case 10:
Input: b=12345
Expected One's Complement: Invalid binary number
Expected Two's Complement: Invalid binary number

You might also like