Amazon | OA | Minimum operation | Minimum Addition
Anonymous User
1716

Q1) Minimum Addition

long long solve(long long n){
  string s=to_string(n);
  sort(s.begin(),s.end());
  string s1="",s2="";
  for(int i=0;i<s.size();i++){
    if(i&1)
      s2+=s[i];
    else
      s1+=s[i];
  }
  long long n1=stol(s1),n2=stol(s2);
  return n1+n2;
}

Q2) You are given an array A containing N integers. You are also given an integer K. An array is good if A[i]<=A[i + k], i=1, 2, 3,.., n - k In one operation, you can choose any element and convert it to an arbitrary integer.

Task

Determine the minimum number of operations to make the array good. Note: Assume 1-based indexing.

What I triedYou are given an array A containing N integers. You are also given an integer K. An array is good if A[i]<=A[i + k], i = 1, 2, 3,.., n - k In one operation, you can choose any element and convert it to an arbitrary integer.

Task

Determine the minimum number of operations to make the array good. Note: Assume 1-based indexing.

ALL ACCEPTED!

int lis(vector<int> &a,int s,int n,int &size){
  vector<int> t;
  for(int i=s;i<n;i++){
      size++;
      auto it=upper_bound(t.begin(),t.end(),A[i]);
      if(it==t.end())
        t.push_back(A[i]);
      else 
        *it=A[i];
  }
  return t.size(); 
}
int minOperation(vector<int> a,int n,int k){
  int c=0;
  for(int i=0;i<k;i++{
    int s=0;
    int v=lis(A,i,n,s);
    c+=s-val;
  }
  return c;
}
Comments (2)