lesson1practice1
Practice Questions
Question 1
You are given an array of n integers. Write a program to count how many numbers are greater than 100.
- What is the time complexity of your program?
- What is the space complexity of your program?
Question 2
You are given an array of n integers. Write a program to count the number of pairs (i, j) such that arr[i] + arr[j] == 100.
- What is the time complexity of your program?
- What is the space complexity of your program?
Question 3
You are given an array of n integers. Write a program to count the number of pairs (i, j) such that arr[i] + arr[j] == 100 using the two-pointer technique:
- Sort the array.
- Use two pointers,
iat the start andjat the end, moving them based on the sum.
- What is the time complexity of your program?
- What is the space complexity of your program?
Question 4
You are given an array of n integers. Write a program to count the number of triplets (i, j, k) such that arr[i] + arr[j] + arr[k] == 0.
- What is the time complexity of your program?
- What is the space complexity of your program?
Comments