Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
What is the index of the first element in a standard array in languages like C, C++, and Java?
Not quite. Try another option.
Answer:
In most programming languages such as C, C++, and Java, array indexing starts at , so the first element is at index .
Question 2 of 60 · Declaring and processing 1D and 2D arrays · Easy
How many elements can a 2D array declared as int a[3][4] hold?
Not quite. Try another option.
Answer:
A 2D array of size holds elements in total.
Question 3 of 60 · Insertion in an array · Easy
When inserting an element at the beginning of an array of elements, how many existing elements must be shifted?
Not quite. Try another option.
Answer:
To insert at the beginning, all existing elements must shift one position to the right to make space.
Question 4 of 60 · Deletion from array · Easy
What is the worst-case time complexity of deleting an element from an array?
Not quite. Try another option.
Answer:
Deleting an element (e.g., from the beginning) requires shifting the remaining elements, giving time in the worst case.
Question 5 of 60 · Array rotations · Easy
If the array is left-rotated by positions, what is the result?
Not quite. Try another option.
Answer:
A left rotation by moves the first two elements to the end, producing .
Question 6 of 60 · Matrix multiplication · Easy
To multiply matrix of size with matrix , what must be true?
Not quite. Try another option.
Answer: Columns of equal rows of
Matrix multiplication requires the number of columns of to equal the number of rows of .
Question 7 of 60 · Lower triangular and upper triangular matrix of array · Easy
In an upper triangular matrix, which elements are zero?
Not quite. Try another option.
Answer: All elements below the main diagonal
In an upper triangular matrix, every element below the main diagonal is zero, while the diagonal and above may be non-zero.
Question 8 of 60 · Print a matrix in spiral form · Easy
When printing a matrix in spiral form, in which order are the boundaries typically traversed first?
Not quite. Try another option.
Answer: Top row, right column, bottom row, left column
Spiral traversal usually goes across the top row, down the right column, across the bottom row, then up the left column, repeating inward.
Question 9 of 60 · String declaration and manipulation · Easy
In C, which character marks the end of a string stored in a character array?
Not quite. Try another option.
Answer: Null character \0
In C, strings are terminated by the null character \0, which indicates the end of the string.
Question 10 of 60 · Missing characters to make a string Pangram · Easy
A pangram is a sentence that contains:
Not quite. Try another option.
Answer: Every letter of the alphabet at least once
A pangram is a sentence that uses every letter of the alphabet at least once, such as "The quick brown fox jumps over the lazy dog".
Question 11 of 60 · Remove minimum number of characters so that two strings become anagram · Easy
Two strings are anagrams of each other if they:
Not quite. Try another option.
Answer: Contain the same characters with the same frequencies
Anagrams contain exactly the same characters with the same counts, just arranged in a different order.
Question 12 of 60 · Creation of stack using arrays · Easy
A stack follows which principle for insertion and removal of elements?
Not quite. Try another option.
Answer: LIFO (Last In First Out)
A stack works on the LIFO principle, where the last element pushed is the first one to be popped.
Question 13 of 60 · Creation of queue using array · Easy
A queue follows which order for processing elements?
Not quite. Try another option.
Answer: FIFO (First In First Out)
A queue processes elements in FIFO order, where the first element added is the first one removed.
Question 14 of 60 · Circular Queue · Easy
What advantage does a circular queue have over a simple linear queue implemented with arrays?
Not quite. Try another option.
Answer: It reuses empty spaces created after dequeuing
A circular queue wraps around to reuse freed positions, avoiding the wasted space problem of a linear queue.
Question 15 of 60 · Implementation of Deque using circular array · Easy
In a deque (double-ended queue), insertion and deletion can be performed at:
Not quite. Try another option.
Answer: Both the front and the rear
A deque allows insertion and deletion of elements from both ends, unlike a standard queue.
Question 16 of 60 · Two pointer technique depicted by problem to find if there exists a pair in an unsorted array whose sum is equal to X · Easy
The two-pointer technique for finding a pair with a given sum is most efficiently applied to an array that is:
Not quite. Try another option.
Answer: Sorted
The two-pointer approach works efficiently on a sorted array, moving pointers inward based on the comparison of the current sum with the target.
Question 17 of 60 · Finding a peak element in array · Easy
A peak element in an array is an element that is:
Not quite. Try another option.
Answer: Greater than or equal to its neighbors
A peak element is one that is greater than or equal to its adjacent neighbors; an array may have multiple peaks.
Question 18 of 60 · Find the majority element · Easy
In an array of size , the majority element is one that appears:
Not quite. Try another option.
Answer: More than times
The majority element occurs more than times, meaning it dominates over half of the array.
Question 19 of 60 · Find the first non-repeating element in a given array of integers · Easy
In the array , what is the first non-repeating element?
Not quite. Try another option.
Answer:
Elements and repeat, so scanning left to right the first element occurring only once is .
Question 20 of 60 · Move All Zeros to End of Array · Easy
After moving all zeros to the end of while keeping the order of non-zero elements, the result is:
Not quite. Try another option.
Answer:
The non-zero elements keep their relative order at the front () and all zeros are moved to the end.
Question 21 of 60 · Array rotations · Medium
An array arr = [1, 2, 3, 4, 5] is left-rotated by 2 positions. What is the resulting array?
Not quite. Try another option.
Answer: [3, 4, 5, 1, 2]
A left rotation by 2 moves the first 2 elements to the end. Elements shift left, so [1,2,3,4,5] becomes [3,4,5,1,2].
Question 22 of 60 · Insertion in an array · Medium
To insert an element at index in an array of size (with space available), how many elements must be shifted in the worst case?
Not quite. Try another option.
Answer:
All elements from index to must shift one position right, which is elements. The worst case (insertion at the front, ) shifts all elements.
Question 23 of 60 · Matrix multiplication · Medium
Two matrices of dimension and of dimension can be multiplied as only if:
Not quite. Try another option.
Answer:
For matrix multiplication , the number of columns of () must equal the number of rows of (). The result has dimension .
Question 24 of 60 · Print a matrix in spiral form · Medium
For the matrix , what is the spiral order traversal starting from the top-left?
Not quite. Try another option.
Answer: 1 2 3 6 9 8 7 4 5
Spiral traversal goes right across the top row (1,2,3), down the right column (6,9), left across the bottom (8,7), up the left column (4), then the center (5).
Question 25 of 60 · Lower triangular and upper triangular matrix of array · Medium
In a square matrix , an element belongs to the upper triangular part when:
Not quite. Try another option.
Answer:
The upper triangular part contains elements on or above the main diagonal, i.e., where the row index does not exceed the column index ().
Question 26 of 60 · Two pointer technique depicted by problem to find if there exists a pair in an unsorted array whose sum is equal to X · Medium
To use the two-pointer technique to find a pair summing to , what preprocessing step is required on an unsorted array?
Not quite. Try another option.
Answer: Sort the array first
The two-pointer approach requires a sorted array so that moving the left pointer increases the sum and moving the right pointer decreases it. Sorting takes , then the scan is .
Question 27 of 60 · Find the majority element · Medium
In the array [3, 3, 4, 2, 3, 3, 5, 3], which element is the majority element (appears more than times)?
Not quite. Try another option.
Answer: 3
The array has 8 elements, so majority requires more than 4 occurrences. Element 3 appears 5 times, which exceeds , making it the majority element.
Question 28 of 60 · Move All Zeros to End of Array · Medium
After moving all zeros to the end of [0, 1, 0, 3, 12] while keeping non-zero order, the result is:
Not quite. Try another option.
Answer: [1, 3, 12, 0, 0]
Non-zero elements retain their relative order (1, 3, 12) at the front, and all zeros are pushed to the end, yielding [1, 3, 12, 0, 0].
Question 29 of 60 · Finding a peak element in array · Medium
A peak element is one that is greater than or equal to its neighbors. In [1, 3, 20, 4, 1, 0], which index holds a peak element?
Not quite. Try another option.
Answer: Index 2 (value 20)
At index 2, the value 20 is greater than its left neighbor (3) and right neighbor (4), so it satisfies the peak condition.
Question 30 of 60 · Missing characters to make a string Pangram · Medium
A pangram contains every letter of the alphabet. For the string "the quick brown fox", how many distinct letters are missing to make it a pangram?
Not quite. Try another option.
Answer: 11
The string uses the distinct letters {t,h,e,q,u,i,c,k,b,r,o,w,n,f,x} = 15 letters. Missing letters are {a,d,g,j,l,m,p,s,v,y,z} = 11 letters.
Question 31 of 60 · Remove minimum number of characters so that two strings become anagram · Medium
Given strings "bcadeh" and "hea", what is the minimum number of characters to remove from both so they become anagrams of each other?
Not quite. Try another option.
Answer: 3
Common characters are {a,e,h}. The first string has 3 extra characters (b,c,d) and the second has 0 extra. Total removals = 3.
Question 32 of 60 · Rearrange characters so that no two adjacent characters are same · Medium
For which string is it impossible to rearrange so that no two adjacent characters are the same?
Not quite. Try another option.
Answer: "aaab"
Rearrangement is possible only if the most frequent character count . In "aaab" (), 'a' appears 3 times but , so it is impossible.
Question 33 of 60 · Implement Stack using Queues · Medium
When implementing a stack using two queues with a costly push operation, what happens during a push?
Not quite. Try another option.
Answer: The new element is enqueued, then all previous elements are dequeued and re-enqueued behind it
In the costly-push approach, the newest element is placed at the front by enqueuing it, then rotating all older elements behind it. This makes push and pop .
Question 34 of 60 · Circular Queue · Medium
In a circular queue of size implemented with an array, after enqueue the rear pointer is updated as:
Not quite. Try another option.
Answer: rear = (rear + 1) % n
The modulo operation with size wraps the rear pointer back to the start when it reaches the end, enabling circular reuse of array slots.
Question 35 of 60 · Implement two Stacks in an array · Medium
When implementing two stacks in a single array of size efficiently, where should the two stacks begin growing from?
Not quite. Try another option.
Answer: One from the start (index 0) growing forward, the other from the end (index ) growing backward
Starting stacks at opposite ends and growing them toward each other maximizes space usage. Overflow occurs only when the two tops meet, unlike a fixed 50-50 split.
Question 36 of 60 · Count subarrays having an equal sum of elements at even and odd positions · Medium
For counting subarrays where the sum of even-indexed elements equals the sum of odd-indexed elements, a common technique uses:
Not quite. Try another option.
Answer: A prefix-difference (even minus odd) with a hash map of first occurrences
By tracking the running difference (even-position sum minus odd-position sum) and counting equal difference values via a hash map, subarrays with balanced sums can be counted in .
Question 37 of 60 · Rearrange array such that even index elements are smaller and odd index elements are greater · Medium
After rearranging [4, 3, 7, 8, 6, 2, 1] so that even-index elements are smaller than their odd-index neighbors (a wave-like pattern), which is a valid result?
Not quite. Try another option.
Answer: [3, 4, 7, 8, 2, 6, 1]
A valid wave arrangement satisfies arr[even] < arr[odd] at each pair boundary. In [3,4,7,8,2,6,1]: 3<4, 7<8, 2<6 all hold, and 4>7 boundaries are managed correctly.
Question 38 of 60 · Find the first non-repeating element in a given array of integers · Medium
In the array [9, 4, 9, 6, 7, 4], what is the first non-repeating element?
Not quite. Try another option.
Answer: 6
Counting frequencies: 9 appears twice, 4 appears twice, 6 once, 7 once. Scanning left to right, the first element with frequency 1 is 6.
Question 39 of 60 · Last Moment Before All Ants Fall Out of a Plank · Medium
On a plank of length , ants moving toward each other pass through without changing direction. For finding the last moment before all ants fall off, the key insight is:
Not quite. Try another option.
Answer: Two colliding ants passing through are equivalent to two ants continuing in their original directions
Since ants are indistinguishable, a collision (both reversing) is equivalent to them passing through. So the answer is simply the maximum of distances each ant must travel to its nearest plank edge.
Question 40 of 60 · Reversing a Queue · Medium
Which data structure is most naturally used to reverse a queue while preserving the queue's FIFO interface?
Not quite. Try another option.
Answer: A stack
Dequeue all elements and push them onto a stack, then pop from the stack and enqueue back. The stack's LIFO order reverses the queue in time.
Question 41 of 60 · Array rotations · Hard
An array A of size is left-rotated by positions using the reversal algorithm (reverse , reverse , then reverse the whole array). For and , what is the resulting array?
Not quite. Try another option.
Answer:
Effective rotation is . Left-rotating by 3 gives .
Question 42 of 60 · Print a matrix in spiral form · Hard
For an matrix printed in spiral order, how many direction-boundary shrink operations (adjusting top/bottom/left/right) occur in total during traversal?
Not quite. Try another option.
Answer: Exactly 4 boundary variables are adjusted a total that scales with
Each full loop of the spiral peels one layer, shrinking boundaries. The number of layers is , so total boundary adjustments scale with , not with .
Question 43 of 60 · Find the majority element · Hard
Using the Boyer-Moore Voting Algorithm on , what are the final candidate and count values just before the verification pass?
Not quite. Try another option.
Answer: candidate , count
Tracing: 2(c=2,cnt=1),2(cnt=2),1(cnt=1),1(cnt=0),1(c=1,cnt=1),2(cnt=0),2(c=2,cnt=1). Final candidate is 2 with count 1, and 2 is indeed the majority.
Question 44 of 60 · Implement two Stacks in an array · Hard
Two stacks are implemented in a single array of size using the space-efficient approach (stack1 grows from index 0, stack2 grows from index ). What is the correct overflow condition when pushing to either stack, given tops top1 and top2?
Not quite. Try another option.
Answer: top1 + 1 == top2
Overflow happens only when the two stacks meet, i.e., there is no gap between them. If top1 + 1 == top2, no free slot remains, so any push overflows.
Question 45 of 60 · Remove minimum number of characters so that two strings become anagram · Hard
For strings s1 = "bcadeh" and s2 = "hea", what is the minimum number of characters to delete (from either string) to make them anagrams of each other?
Not quite. Try another option.
Answer:
Common characters (by frequency) are a, e, h — 3 chars. s1 has 6 chars, s2 has 3. Deletions . Equivalently, sum of absolute frequency differences .
Question 46 of 60 · Last Moment Before All Ants Fall Out of a Plank · Hard
On a plank of length , ants moving left are at positions and ants moving right are at . When two ants collide they reverse direction. What is the last moment before all ants fall off?
Not quite. Try another option.
Answer:
Collisions are equivalent to ants passing through each other. Left-movers fall at their own position (max ); right-movers fall at (max ... wait).
Question 47 of 60 · Two pointer technique depicted by problem to find if there exists a pair in an unsorted array whose sum is equal to X · Hard
To find whether a pair sums to in an unsorted array using the two-pointer technique, what preprocessing is required and what is the resulting overall time complexity?
Not quite. Try another option.
Answer: Sort first, giving overall
The two-pointer method requires a sorted array. Sorting costs and the scan costs , so the dominant term is .
Question 48 of 60 · Count subarrays having an equal sum of elements at even and odd positions · Hard
The trick to count subarrays where the sum of even-indexed and odd-indexed elements are equal is to negate elements at odd positions and then:
Not quite. Try another option.
Answer: count subarrays with sum using prefix-sum frequencies
Negating odd-index elements makes 'even-sum = odd-sum' equivalent to 'subarray sum '. Using a hash map of prefix-sum counts, this is countable in .
Question 49 of 60 · Finding a peak element in array · Hard
Binary search finds a peak element (an element its neighbors) in . If A[mid] < A[mid+1], which direction guarantees a peak exists?
Not quite. Try another option.
Answer: Search the right half (mid+1 .. hi)
If A[mid] < A[mid+1], the sequence is ascending to the right, so a peak must exist on the right side (the array boundary acts as ). Move to mid+1 .. hi.
Question 50 of 60 · Rearrange characters so that no two adjacent characters are same · Hard
A rearrangement of a string with no two adjacent equal characters is possible if and only if the maximum character frequency maxFreq satisfies which condition for a string of length ?
Not quite. Try another option.
Answer:
The most frequent character can occupy alternate slots. There are such slots, so a valid arrangement exists iff .
Question 51 of 60 · Design a stack with operations on middle element · Hard
To support push, pop, and findMiddle/deleteMiddle all in , which data structure is used and why?
Not quite. Try another option.
Answer: A doubly linked list with a pointer to the middle node
A doubly linked list allows updating the middle pointer in on each push/pop (moving it based on size parity), and its bidirectional links let deletion of the middle node happen in constant time.
Question 52 of 60 · Implementation of Deque using circular array · Hard
In a deque implemented with a circular array of capacity , indices front and rear, which expression correctly moves front backward during insertFront?
Not quite. Try another option.
Answer: front = (front - 1 + n) % n
Moving front backward may go below 0. Adding before taking mod ensures a non-negative wrapped index, e.g., front .
Question 53 of 60 · Implement Stack using Queues · Hard
When implementing a stack using a single queue, making push the costly operation, what is the sequence of steps for push(x) on a queue currently holding elements?
Not quite. Try another option.
Answer: Enqueue , then dequeue and re-enqueue the first elements
After enqueuing , rotating the previous elements to the back places at the front, so it will be dequeued first — mimicking LIFO. Push is , pop is .
Question 54 of 60 · Missing characters to make a string Pangram · Hard
For the string "the quick brown fox" (ignoring spaces, lowercase), how many distinct letters must be added to make it a pangram?
Question 55 of 60 · Move All Zeros to End of Array · Hard
Using the two-pointer approach with a insertPos pointer, how many swaps occur for A = [0, 1, 0, 3, 12] while preserving the order of non-zero elements?
Not quite. Try another option.
Answer:
Non-zeros 1, 3, 12 are each swapped into insertPos (indices 0,1,2) while zeros drift right. That is 3 swaps, yielding with relative order preserved.
Question 56 of 60 · Check if all bits can be made same by single flip · Hard
A single flip means toggling exactly one contiguous group of adjacent same-bits. All bits can be made same by a single flip iff the number of 'groups' of consecutive equal bits is at most:
Not quite. Try another option.
Answer:
If there are at most 2 groups (e.g., 000111 or 111), flipping one group makes all bits equal. With 3 or more groups, a single group flip cannot unify all bits.
Question 57 of 60 · Lower triangular and upper triangular matrix of array · Hard
For an matrix, how many elements belong strictly to the upper triangular part (excluding the main diagonal)?
Not quite. Try another option.
Answer:
Total off-diagonal elements , split equally between strict upper and lower parts. So the strict upper triangle has elements.
Question 58 of 60 · Find the first non-repeating element in a given array of integers · Hard
Which approach finds the first non-repeating element in optimal time, and what is that complexity for elements?
Not quite. Try another option.
Answer: Two passes with a hash map of counts,
First pass builds frequency counts; second pass scans in order returning the first element with count 1. Both passes are linear, giving time and space.
Question 59 of 60 · Rearrange array such that even index elements are smaller and odd index elements are greater · Hard
For a valid 'wave-like' arrangement where A[0] < A[1] > A[2] < A[3] > ..., which single-pass swapping rule achieves this in without sorting?
Not quite. Try another option.
Answer: For each odd index , swap with if A[i-1] > A[i], and with if A[i+1] > A[i]
Iterating over odd positions and ensuring each is greater than both neighbors (swapping when a neighbor is larger) produces the wave pattern in one linear pass, avoiding the sort.
Question 60 of 60 · K maximum sum from two arrays · Hard
Given two sorted (descending) arrays, to find the maximum pairwise sums , the efficient approach uses a max-heap starting with which pair, and pushes which neighbors after each extraction?
Not quite. Try another option.
Answer: Start with ; after popping push and with a visited set
The largest sum is . Each extracted pair's two 'right/down' neighbors are the next candidates; a visited set prevents duplicates. This yields the top sums in .
That's unit 1
Answer a few questions and your score shows up here.
Nearly through. Did unit 1 of CSE329 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 1 of CSE329 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.