Level 3
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.
Constraints:
1{𝐴 𝑎𝑝𝑝𝑒𝑎𝑟𝑠 𝑚𝑜𝑟𝑒 𝑡ℎ𝑎𝑛 𝑜𝑛𝑐𝑒 𝑖𝑛 𝐴} is the indicator function that evaluates to 1 if the
𝑖
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.
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.
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:
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.
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.
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.
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].
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.
transaction = [𝑡1, 𝑡2, 𝑡3, ... , 𝑡𝑛] → An array representing transaction identifiers
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
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.
B → Target sum
Constraints:
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.
Constraints:
5
● 1<=[Link]<=10
● -100<=nums[i]<=100
● nums is sorted in non-decreasing order
● n>0
Constraints:
● The matrix A is symmetric if it satisfies:
𝑇 𝑇
𝐴 = 𝐴 , 𝑤ℎ𝑒𝑟𝑒 𝐴 𝑖𝑠 𝑡ℎ𝑒 𝑡𝑟𝑎𝑛𝑠𝑝𝑜𝑠𝑒 𝑜𝑓 𝐴
● m==n
● 1<m,n<=10
● -100 <= 𝐴𝑖𝑗<=100
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