1D- Array
1. Print all elements of an array.
2. Find the sum of all elements in an array.
3. Find the largest element in an array.
4. Find the smallest element in an array.
5. Count even and odd numbers in an array.
6. Copy one array into another.
7. Print array in reverse order.
8. Count number of positive elements.
9. Search an element using linear search.
10. Find the average of array elements.
11. Input and print a 2D array (matrix).
12. Find the sum of all elements of matrix.
YOU CAN ALSO TRY THESE QUESTIONS
1. Given an array of integers nums and an integer target,
return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution,
and you may not use the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
2.
You are given two integer arrays nums1 and nums2, sorted in non-
decreasing order, and two integers m and n, representing the
number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-decreasing
order.
The final sorted array should not be returned by the function, but
instead be stored inside the array nums1. To accommodate
this, nums1 has a length of m + n, where the first m elements denote
the elements that should be merged, and the last n elements are set
to 0 and should be ignored. nums2 has a length of n.
Example 1:
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
The result of the merge is [1,2,2,3,5,6] with the underlined elements
coming from nums1.
Example 2:
Input: nums1 = [1], m = 1, nums2 = [], n = 0
Output: [1]
Explanation: The arrays we are merging are [1] and [].
The result of the merge is [1].
Example 3:
Input: nums1 = [0], m = 0, nums2 = [1], n = 1
Output: [1]
3.
Given a non-empty array of integers nums, every element
appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and
use only constant extra space.
Example 1:
Input: nums = [2,2,1]
Output: 1
Example 2:
Input: nums = [4,1,2,1,2]
Output: 4
Example 3:
Input: nums = [1]
Output: 1
4.
Given an array of integers nums, calculate the pivot index of this
array.
The pivot index is the index where the sum of all the
numbers strictly to the left of the index is equal to the sum of all the
numbers strictly to the index's right.
If the index is on the left edge of the array, then the left sum
is 0 because there are no elements to the left. This also applies to the
right edge of the array.
Return the leftmost pivot index. If no such index exists, return -1.
Example 1:
Input: nums = [1,7,3,6,5,6]
Output: 3
Explanation:
The pivot index is 3.
Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11
Right sum = nums[4] + nums[5] = 5 + 6 = 11
Example 2:
Input: nums = [1,2,3]
Output: -1
Explanation:
There is no index that satisfies the conditions in the problem
statement.
Example 3:
Input: nums = [2,1,-1]
Output: 0
Explanation:
The pivot index is 0.
Left sum = 0 (no elements to the left of index 0)
Right sum = nums[1] + nums[2] = 1 + -1 = 0
Stack
1 Find the top element of stack.
2 Reverse a string using stack.
3 Convert a string to stack and print.
4 Count total elements in stack.
5 Implement stack using array.
YOU CAN ALSO TRY THESE QUESTIONS
Given a string s containing just the
characters '(', ')', '{', '}', '[' and ']', determine if the input string
is valid.
An input string is valid if:
1. Open brackets must be closed by the same type of
brackets.
2. Open brackets must be closed in the correct order.
3. Every close bracket has a corresponding open bracket of
the same type.
Example 1:
Input: s = "()"
Output: true
Example 2:
Input: s = "()[]{}"
Output: true
Example 3:
Input: s = "(]"
Output: false
Example 4:
Input: s = "([])"
Output: true
Example 5:
Input: s = "([)]"
Output: false
2.
Postfix Expression Evaluation
Example 1:
Input: s = ”23+5-“
Output: 0
Explaination:
2+3 5-
5 5-
0
Ans= 0
Queue
1 Enqueue an element.
2 Dequeue an element.
3 Display all elements of queue.
4 Check whether queue is empty.
5 Find the front element.
6 Count total elements in queue.
7 Implement queue using array.
8 Insert 5 elements and print queue.
9 Delete an element and print queue.