Question: Deloitte, Recent Online Assessment (30th August 2023) | Position of Number in a given array | List A of N integers
0
Entering edit mode

ADD COMMENTlink 14 months ago PoGo 2.4k
0
Entering edit mode

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)
ADD COMMENTlink 14 months ago Dp • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts