Phase 4 - Level 5: Logical & Applied
Apply array logic to solve complex problems.
14 programs · open one, then the next
Start with Check if Array is Sorted (Ascending)- 01Check if Array is Sorted (Ascending)AdvancedCheck nondecreasing order in a list by comparing neighbors. Students use a boolean flag, stop on the first inversion, and understand how ties are handled.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 02Check if Array is Sorted (Descending)AdvancedCheck nonincreasing order in a list with adjacent comparisons. Students identify the first upward step and see why descending order can include equal neighbors.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 03Find Second LargestAdvancedFind the second distinct largest value in a list. Students skip every maximum, track a nullable candidate, and distinguish distinct rank from sorted position.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 04Find Second SmallestAdvancedFind the second distinct smallest list value with Python. Students exclude all copies of the minimum and use None until a valid replacement candidate appears.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 05Range (Max - Min)AdvancedCalculate a list's numerical range as maximum minus minimum. Students guard empty input and distinguish this statistical range from the range iterator.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 06Sum Except Max & MinAdvancedSum list entries after excluding one maximum and one minimum. Students trace totals and see why repeated extreme values are not all removed by subtraction.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 07Count Pairs with Sum KAdvancedCount unordered index pairs whose values add to a target. Students trace nested bounds and avoid counting a pair twice or pairing an element with itself.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 08Count Elements Greater Than AverageAdvancedCount values strictly above a list's average. Students compute the mean first, scan again for matches, and identify empty input as an undefined case here.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 09Frequency of Distinct ElementsAdvancedPrint a count for each distinct integer in sorted order with Python. Students combine a frequency dictionary, a set of keys, and numeric ordering for display.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 10Unique Elements OnlyAdvancedRemove repeated list values while preserving first appearances in Python. Students pair a set for membership with a result list for stable output order.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 11Find Kth Largest ElementAdvancedSelect the kth largest list position with Python sorted. Students validate a one-based rank, convert it to an index, and retain repeated values as ranks.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 12Rotate Array by K PositionsAdvancedRotate a list right by k positions using slices. Students normalize the count, join the wrapped suffix and prefix, and handle zero-sized input before modulo.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 13Find Missing Number in SequenceAdvancedFind one missing value from one through n using sums. Students trace the triangular-number formula and see the exact input assumptions behind subtraction.Open example →py# Take array n = int(input("Enter n (expected range 1 to n): ")) arr = [] for i in range(n - 1):
- 14Find Duplicate ElementAdvancedFind a duplicate by subtracting expected and actual sequence sums. Students examine a shortcut that depends on every value from one through n being present.Open example →py# Take array n = int(input("Enter n: ")) arr = [] for i in range(n + 1):