let's understand it in a crispy way, simple explanation with YouTube Video
YouTube explanation https://youtu.be/Lyssy7pJLE4\n# Intuition and approach\nlets keep it simple with below steps:-\n \n1) sort the items array based on price\n2
# YouTube explanation https://youtu.be/Lyssy7pJLE4\n# Intuition and approach\nlets keep it simple with below steps:-\n \n**1)** sort the items array based on price\n**2)** make a **queryIndex[][] = new int[n][2]**, where n = queries.length\n**queryIndex[i][0] == price,  queryIndex[i][1] == index** in queires array\n\n**why should make this??** ===> because we want to sort the array based on price in increasing order, but also want to keep track their orginal index otherwise we will loose the index info to put it  in array.\n\nNOW we will also sort the **queryIndex array based on price**.\n\nnow we will create an answer array **ans[] = new int[n]**\n\nnow we will start with **itemIndex = 0 , and a variable say maxBeauty =0**\n\n\nso for **i = to i = n-1** \ncurrPrice = queryIndex[i][0]\ncurrIndex = queryIndex[i][1]\nnow we will search the value in Items array till we get the price that is smaller or equal to **currPrice** and we will record the max value during this loop.\n\nassign the maxvalue ans[currIndex] = maxVal;\n\nrepeat it till the for loop ends and return ans.\n\n**will relase a youtube video soon to explain everything in details**\n\n\n\n# Code\n```java []\n\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] queries) {\n    int n = queries.length;\n    int ans[] = new int[n];    \n\n    int[][]queryIndex = new int[n][2];\n    for(int i=0; i<n; i++)\n    {\n        queryIndex[i][0] = queries[i];\n        queryIndex[i][1] = i; \n    }\n    Arrays.sort(queryIndex, (a, b)->a[0]-b[0]);\n    Arrays.sort(items, (a, b)-> a[0]-b[0]);\n\n   \n    int maxBeauty = 0; \n    int itemIndex = 0; \n\n    for(int i=0; i<n; i++)\n    {\n      int currIndex = queryIndex[i][1];\n      int currPrice = queryIndex[i][0];\n      while(itemIndex<items.length && currPrice>=items[itemIndex][0])\n      {\n        maxBeauty = Math.max(maxBeauty, items[itemIndex][1]);\n        itemIndex++;\n      }\n      ans[currIndex] = maxBeauty;\n    }\n  \n     return ans;\n    \n    }\n}\n```
['Array', 'Math', 'Binary Search', 'Sorting', 'Java']