DSA Assignment 1 Solution
DSA Assignment 1 Solution
Solution 1 Link –
https://leetcode.com/problems/kids-with-the-greatest-number-of-
candies/submissions/1374528119/
Screenshot:
Description:
Iterating to the entire n-sized array and for each array element compared to greatestNo in first
loop that will be O(n)
And in second loop again Iterating to the entire n-sized array and for each array element sum
with extraCandies compared to greatestNo will be O(n)
The resultArray stores the results for each kid, so it will have the same length as the candies
array, which is n. so Space Complexity: O(n)
Solution 2 Link –
https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-
k/submissions/1374541996/
Screenshot:
Description:
Time Complexity: O(n2)
Iterating to the entire n-sized array and again Iterating to the (n-i) sized array then
perform the operation that will be O(n*n) = O(n2)
Space complexity: O(1)
No Extra space required for the Program Execution
Question 3 was https://leetcode.com/problems/find-common-elements-between-two-arrays/
Solution 3 Link –
https://leetcode.com/problems/find-common-elements-between-two-
arrays/submissions/1374572685/
Screenshot:
Description:
Time Complexity: O(n*m)
Iterating to the entire n-sized array and again Iterating to the (m) sized array then perform
the operation that will be O(n*m)
This will perform 2 times
Total Time Complexity = O(n*m) + O(n*m) = O(n*m)
Space complexity: O(1)
No Extra space required for the Program Execution
Question 4 was https://leetcode.com/problems/number-of-good-pairs/
Solution 4 Link –
https://leetcode.com/problems/number-of-good-pairs/submissions/1374582852/
Screenshot:
Description:
Time Complexity: O(n2)
Iterating to the entire n-sized array and again Iterating to the (n-i) sized array then
perform the operation that will be O(n*(n-1))
Solution 5 Link –
https://leetcode.com/problems/shuffle-the-array/submissions/1374591325/
Screenshot:
Description:
Time Complexity: O(n)
Iterating to the entire n-sized array and for each array element performing O(1) operation
of push.