Arrays Practice Sheet
Beginner Level Questions
1. Create an array and print its elements.
Question: Ek array banao aur uske elements print karo.
Explanation: Yah code ek array create karta hai aur console me uske elements ko print karta hai.
2. Find the length of an array.
Question: Array ki length find karo.
Explanation: length
property use karke array ki total length ya elements ki sankhya nikaali ja sakti hai.
3. Access the first element of an array.
Question: Array ke pehle element ko access karo.
Explanation: Array ke first element ko access karne ke liye index 0 use hota hai.
4. Access the last element of an array.
Question: Array ke last element ko access karo.
Explanation: Last element ko access karne ke liye, array length se 1 minus karte hain.
5. Add an element at the end of an array.
Question: Array ke end me ek element add karo.
Explanation: push
method use karke hum array ke end me new element add kar sakte hain.
6. Remove the last element from an array.
Question: Array ke last element ko remove karo.
Explanation: pop
method use karke array ke last element ko remove karte hain.
7. Add an element at the beginning of an array.
Question: Array ke beginning me ek element add karo.
Explanation: unshift
method array ke beginning me new element add karne ke liye use hota hai.
8. Remove the first element from an array.
Question: Array ke first element ko remove karo.
Explanation: shift
method array ke first element ko remove karta hai.
9. Concatenate two arrays.
Question: Do arrays ko concatenate (milana) karo.
Explanation: concat
method use karke do arrays ko combine kar sakte hain.
10. Check if an array contains a specific element.
Question: Check karo ki array me specific element hai ya nahi.
Explanation: includes
method check karta hai ki given element array me hai ya nahi.
Intermediate Level Questions
11. Reverse an array.
Question: Array ko reverse karo.
Explanation: reverse
method array ke elements ko reverse kar deta hai.
12. Sort an array in ascending order.
Question: Array ko ascending order me sort karo.
Explanation: sort
method aur comparison function use karke array ko ascending order me sort karte hain.
13. Sort an array in descending order.
Question: Array ko descending order me sort karo.
Explanation: sort
method aur comparison function use karke array ko descending order me sort karte hain.
14. Find the index of a specific element.
Question: Specific element ka index find karo.
Explanation: indexOf
method use karke kisi element ka index nikaalte hain.
15. Remove a specific element by its index.
Question: Specific element ko uske index se remove karo.
Explanation: splice
method use karke kisi element ko uske index se remove karte hain.
16. Create a new array with only even numbers.
Question: Naya array banao jisme sirf even numbers ho.
Explanation: filter
method use karke array se even numbers ko filter karte hain.
17. Sum all elements of an array.
Question: Array ke saare elements ka sum find karo.
Explanation: reduce
method use karke array ke saare elements ka sum nikaalte hain.
18. Find the maximum element in an array.
Question: Array me maximum element find karo.
Explanation: Math.max
function aur spread operator use karke array me max element find karte hain.
19. Find the minimum element in an array.
Question: Array me minimum element find karo.
Explanation: Math.min
function aur spread operator use karke array me min element find karte hain.
20. Flatten a nested array.
Question: Nested array ko flatten karo.
Explanation: flat
method use karke nested array ko flatten karte hain.
21. Remove duplicate elements from an array.
Question: Array se duplicate elements ko remove karo.
Explanation: Set
aur spread operator use karke array se duplicates remove karte hain.
22. Merge two arrays and remove duplicates.
Question: Do arrays ko merge karo aur duplicates remove karo.
Explanation: Set
aur spread operator use karke do arrays ko merge karte hain aur duplicates remove karte hain.
23. Create an array of the first n Fibonacci numbers.
Question: Pehle n Fibonacci numbers ka array banao.
Explanation: Yah function pehle n Fibonacci numbers ko generate karke array me return karta hai.
24. Create an array of squares of each element.
Question: Har element ka square nikal ke array banao.
Explanation: map
method use karke har element ka square nikaal ke new array banate hain.
25. Find all elements greater than a specific value.
Question: Specific value se greater saare elements find karo.
Explanation: filter
method use karke specific value se greater elements ko filter karte hain.
26. Check if all elements are positive.
Question: Check karo ki saare elements positive hain ya nahi.
Explanation: every
method use karke check karte hain ki saare elements positive hain ya nahi.
27. Find the difference between the largest and smallest numbers.
Question: Largest aur smallest number ke beech ka difference find karo.
Explanation: Math.max
aur Math.min
functions use karke difference nikaalte hain.
28. Rotate an array by k positions.
Question: Array ko k positions se rotate karo.
Explanation: slice
aur spread
operator use karke array ko k positions se rotate karte hain.
29. Find the second largest element in an array.
Question: Array me second largest element find karo.
Explanation: Pehle largest element remove karte hain aur fir bacha hua max element nikaalte hain.
30. Implement a function to find the intersection of two arrays.
Question: Do arrays ke intersection elements find karne ka function banao.
Explanation: filter
aur includes
method use karke do arrays ke common elements find karte hain.
Advanced Level Questions
31. Find the union of two arrays.
Question: Do arrays ka union find karo.
Explanation: Set
aur spread operator use karke do arrays ka union banate hain.
32. Find the symmetric difference of two arrays.
Question: Do arrays ka symmetric difference find karo.
Explanation: filter
aur includes
method use karke symmetric difference nikaalte hain.
33. Implement binary search on a sorted array.
Question: Sorted array par binary search implement karo.
Explanation: Binary search algorithm use karke sorted array me target element find karte hain.
34. Find the first duplicate element in an array.
Question: Array me pehla duplicate element find karo.
Explanation: Set
use karke pehla duplicate element find karte hain.
35. Group elements of an array based on their frequency.
Question: Array ke elements ko unki frequency ke base par group karo.
Explanation: reduce
aur map
methods use karke elements ko unki frequency ke base par group karte hain.
36. Find the subarray with the maximum sum (Kadane’s Algorithm).
Question: Maximum sum wala subarray find karo (Kadane’s Algorithm).
Explanation: Kadane’s Algorithm use karke maximum sum subarray find karte hain.
37. Find the longest increasing subsequence.
Question: Longest increasing subsequence find karo.
Explanation: Dynamic programming approach use karke longest increasing subsequence find karte hain.
38. Rotate an array to the right by k steps.
Question: Array ko right side se k steps se rotate karo.
Explanation: slice
aur spread
operator use karke array ko right side se k steps rotate karte hain.
39. Find the majority element (element appearing more than n/2 times).
Question: Majority element find karo (jo n/2 times se zyada appear hota hai).
Explanation: Boyer-Moore Voting Algorithm use karke majority element find karte hain.
40. Find the missing number in an array of 1 to n.
Question: 1 se n tak ke array me missing number find karo.
Explanation: Total sum of 1 to n aur array sum ke difference se missing number find karte hain.
41. Find the peak element in an array.
Question: Array me peak element find karo.
Explanation: Linear search use karke peak element find karte hain jo apne dono neighbors se bada hota hai.
42. Find the smallest missing positive number.
Question: Smallest missing positive number find karo.
Explanation: Set
use karke smallest missing positive number find karte hain.
43. Find the maximum product of two integers in an array.
Question: Array me do integers ka maximum product find karo.
Explanation: Pehle do largest numbers find karte hain aur unka product nikaalte hain.
44. Implement the quicksort algorithm.
Question: Quicksort algorithm implement karo.
Explanation: Quicksort algorithm use karke array ko sort karte hain.
45. Find the largest sum of contiguous subarray (Kadane’s Algorithm).
Question: Largest
sum of contiguous subarray find karo (Kadane’s Algorithm).
Explanation: Kadane’s Algorithm use karke largest sum of contiguous subarray find karte hain.
46. Implement merge sort algorithm.
Question: Merge sort algorithm implement karo.
Explanation: Merge sort algorithm use karke array ko sort karte hain.
47. Find the longest common subsequence of two arrays.
Question: Do arrays ka longest common subsequence find karo.
Explanation: Dynamic programming use karke do arrays ka longest common subsequence find karte hain.
48. Implement the radix sort algorithm.
Question: Radix sort algorithm implement karo.
Explanation: Radix sort algorithm use karke array ko sort karte hain.
49. Find the kth smallest element in an unsorted array.
Question: Unsorted array me kth smallest element find karo.
Explanation: Array ko sort karke kth smallest element ko return karte hain.
50. Find the kth largest element in an unsorted array.
Question: Unsorted array me kth largest element find karo.
Explanation: Array ko sort karke kth largest element ko return karte hain.
51. Implement heap sort algorithm.
Question: Heap sort algorithm implement karo.
Explanation: Heap sort algorithm use karke array ko sort karte hain.
52. Find the length of the longest subarray with sum zero.
Question: Sum zero wala longest subarray ka length find karo.
Explanation: Hashmap use karke sum zero wala longest subarray ka length find karte hain.
53. Find the longest palindrome subarray.
Question: Longest palindrome subarray find karo.
Explanation: Nested loops aur helper function use karke longest palindrome subarray find karte hain.