0% found this document useful (0 votes)
10 views

Oracle OA

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Oracle OA

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Maxlmum Knowledge
There Is golng to be a conference for d days. The
schedule of nmeetings is glven as three arrays, s
(star) e (end), and a (additional knowledge galned).
The fh meeting Is avalable from (sU,eldays (both
Incluslve) and provides a knowledge galn of al). A
limit of kmeetings can be attended in one day.
Find the maxlmum knowledge that can ba,galned Jn
a day.
Example
de 10
n=4
k=2
S= 25,4, 3)
e (8, 9, 7,5]
8-[800, 1600, 200, 400
BETA) Can't read the text? Switch theme

22. Question 22

Ashopkeeper in HackLand assigns each item in


a shop a unique popularity rating. To order the
items in decreasing popularity from left to right,
the shopkeeper can swap any 2 items in one
operation. Determine the minimum number of
operations needed toreorder the items
corectly.

Dtample
n=4
popularity-B41,2)

First switch 3and 4to get popularity'=14 3, 1,


Then switch 1and 2to get [4, 3, 2 1).
The array is reordered in 2 operations.

Function Description
Complete the function minimumSwaps in the
editor below.

minimumSwaps has the following parameter(s):


int popularityn]: an array of integers that
represents the popularity of each item
Returns:
int:the minimum number of swaps to order
the items properly
Constraints

" 1sns2x 105


Constraints

" 1sns2 x 105


1spopularitytü sn

Input Format for Custom Testing

7Sample Case 0

Sample Input 0
STDIN Function I
3 popularity[] size n = 3
3 popularity = (3, 1, 2]
1

Sample Output 0
1

Explanation 0
n=3
popularityB1,2]

Switch 1and 2 and the items in the array [3,


2 1]are reordered in 1operation. The return
value is 1.
1. 1 one
int Find(int n, int k,int d, vector<int> S,
vector<int> e){
vector<vector<int>> v;
for(int i=0;i<n;i++) v.push_back({s[i],e[i]});

sort(v.begin(),v.end():
priority_queue<int,vector<int>,greater<int>> pq;
int i-0,day=v[o][o];
int ans=0;

while(i<n or pq.size)){

if(pq.size()==0) day=v[i](0);
while(i<n and v[il[0]<=day){
pq.push(v[l[1);
itt;

int cnt-0;

while(pq.size() and cnt<k){


pg-pop();
cnt++;
ans++;

day++;
if(day>d) break;

while(pq,size() and pq.top()<day) pq.pop():


}

return ans;
2nd
int minSwaps(int arrl], int n)

int len = n;
map<int, int> map;
for (int i= 0; i< len; i++)
map[nums[i]] = i;

sort(nums, nums + n);


reverse(nums,nums+n);
bool visited[len] ={0};
int ans =0;
for (int i=0; i< len; it+){
if (visited ) || map[nums[i]] = i)
continue;

intj =i, cycle_size = 0;


while (!visited i]){
visited [j] =true;
j=map[numsi]l;
cycle_sizet+;
if (cycle_size > 0) {
ans t= (cycle_size - 1);

}
return ans;

You might also like