DAY 1
DAY 1
Problem Description:
Given an array of N integers and an integer K, determine whether K is present in the array.
Pseudocode:
Explanation:
Time Complexity:
Space Complexity:
- Space Complexity: O(1) - Only a few variables are used regardless of the input size.
Problem 2: Find maximum in an Array
Problem Description:
Given a list of N integers representing the heights of mountains, find the height of the tallest
mountain. This has to be done for multiple test cases.
Pseudocode:
function findMaxHeight(testCases):
results = []
for each testCase in testCases:
N = testCase[0]
heights = testCase[1]
max_height = 0
for height in heights:
if height > max_height:
max_height = height
results.append(max_height)
return results
Explanation:
Time Complexity:
Space Complexity:
Problem Description:
Given two arrays of ingredients and costs, where ingredients[i] is the number of units of
ingredient i needed, and costs[i] is the cost per unit of ingredient i, compute the total cost.
Pseudocode:
Explanation:
1. Initialize total_cost to 0.
2. Traverse both arrays (which have the same length):
- Multiply ingredients[i] by costs[i] to get the cost for that ingredient.
- Add this value to total_cost.
3. Return total_cost.
Time Complexity:
Space Complexity:
- Space Complexity: O(1) - Only a few variables are used regardless of the input size.