Question: Deloitte, Recent Online Assessment (30th August 2023) | Position of Number in a given array | List A of N integers QUESTION -1
SOLUTION : -
- int ans = -1;
- for(int i=0;i<arr.size();i++){
- if(arr[i]==x){
- ans = i+1;
- }
- }
- return ans;
- }
Time complexity :- O(n)
Space Complexity :- O(1)
QUESTION -2
SOLUTION : -
- int sum = 0;
- for(int i=0;i<arr.size();i++){
- if(pow(2,i)-1<arr.size()){
- sum+=arr[pow(2,i)-1];
- }
- }
- return sum;
- }
Time complexity :- O(n)
Space Complexity :- O(1)
Login before adding your answer.