Please help me in solving this (java preferably)




Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int[] findTotalShops(int shops,int[]prices,int days,int[] money)
    {
        int [] totalShops=new int[days];
      Arrays.sort(prices);
      for(int i=0;i<days;i++)
      {
          if(money[i]<prices[0])
              totalShops[i] = 0;
          else if(money[i]>=prices[shops-1])
              totalShops[i]=shops;
          else
          totalShops[i]=binarySearch(prices,0,shops-1,money[i]);
      }
      return totalShops;
    }
    public static int binarySearch(int []arr,int low,int high,int money)
    {
       if(arr[low]==money)
           return low+1;
       if(arr[high]<=money)
           return high+1;
       int mid=low+(high-low)/2;
       int maxShops=-1;
       while(arr[mid]==money)
       {
           maxShops=mid;
           mid++;
       }
       if(maxShops!=-1)
           return maxShops+1;
       if(arr[mid]>money)
           return binarySearch(arr,low,mid-1,money);
       else
           return binarySearch(arr,mid+1,high,money);
    }
}

- Bharath May 09, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int[] arr = new int[input3];
for(int i=0;i<input3;i++)
{
arr[i]=0;
for(int j =0;j<input1;j++)
{
if(input4[i]>=input2[j])
{
arr[i]++;
}
}
}
return arr;

- Anonymous June 10, 2020 | Flag Reply




Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More