Answer to Question #253246 in Algorithms for Kartik

Question #253246

A toy shop has a unique way of selling their toys to children. As the shop opens the toys prices keeps increasing for every sale he makes. After some time the shopkeeper prefers to lower the price every sale he makes. For example , say the starting prices of the toy is Rs. 10. He decides to increase the price by 5 for 5 first entries and reduce the price by 5 there after. The list would be 10 15 20 25 30 25 20 15 10 5 0. Given this kind of pricing, every day he wants to find what is the maximum price a child had paid for the toy. Write a program to help the shop keep find the toys price in less than O(n) time. You will be given the array. The number of entries for which the shopkeeper decides to increase is kept as a secret. 


1
Expert's answer
2021-10-18T18:21:33-0400
int max(int *arr) {
  int n = sizeof(arr) / sizeof(int);
  int m = null;
  for (int i = 0; i < n; i++) {
    if (m == null || m < arr[i]) {
      m = arr[i];
    }
  }
  return m;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS