Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,863 views

For proper oa or interview experiences list of all top tech companies visit :

https://oa.desiqna.in

https://interview.desiqna.in

 

image

 

in Online Assessments by Expert (46,090 points) | 1,863 views

2 Answers

0 like 0 dislike
Best answer

Analyzing Arrays
Consider a 1-based array of n integers, arr[n]. For each element arr[i] where 1 <= i < n, determine the value of arr[i] ** arr[i+1] modulo (10 ** 9 + 7).  Return the lowest index of the highest modulo value.

by Expert (46,090 points)
0 like 0 dislike
Solution:

#include <bits/stdc++.h>
using namespace std;
int calculate(int a, int b){
	    return (int)((int)pow(a,b) % (int)(pow(10,9)+7));
	}
int powerArray(vector<int> arr){
    int result = INT_MAX;
    int n = arr.size();
	for(int i=1; i<=n-2; i++){
	    if(calculate(arr[i], arr[i+1])  >= calculate(arr[i+1], arr[i+2])){
	        result = min(result, i);
	    }
	}
	return result+1;
}
by Expert (46,090 points)