By BinarySearch Using Hashing Technique [JAVA] [Optimized Approach]
Binary Search using Hashing technique\n\n Sort the items (2D array) By making a pair class and sort it,\n make another beauty array that store the maximum beaut
**Binary Search** using **Hashing** technique\n\n* Sort the items (2D array) By making a pair class and sort it,\n* make another beauty array that store the maximum beauty of every index till now (According to the sorted items array indexing)  (that will us to achive to get maximum beauty of any index in O(1).\n* now starts traversing on queries ,and on each iteration apply binary search on it.\n\n```\nclass pair {\n\tint p;\n\tint b;\n\n\tpair(int p, int b) {\n\t\tthis.p = p;\n\t\tthis.b = b;\n\t}\n}\n\nclass Solution {\n\tpublic int[] maximumBeauty(int[][] items, int[] q) {\n\n\t\tint n = items.length,i=0;\n\n\t\tpair[] p = new pair[n];\n \n\t\tfor (int[] x : items) {\n\t\t\tint pii = x[0];\n\t\t\tint b = x[1];\n\t\t\tpair pi = new pair(pii, b);\n\t\t\tp[i] = pi;\n\n\t\t\tbe[i] = maxb;\n\t\t\ti++;\n\t\t}\n\n\t\tArrays.sort(p, (a, b) -> {\n\t\t\treturn a.p - b.p;\n\t\t});\n\n\t\ti = 0;\n\t\tint[] be = new int[n];\n\t\tint maxb = Integer.MIN_VALUE;\n\t\t\n\t\tfor (pair x : p) {\n\n\t\t\tmaxb = Integer.max(maxb, x.b);\n\t\t\tbe[i] = maxb;\n\t\t\ti++;\n\t\t}\n\n\t\ti = 0;\n\t\tint[] ans = new int[q.length];\n\n\t\tfor (int x : q) {\n\t\t\tans[i] = search(p, x, be);\n\t\t\ti++;\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\tpublic int search(pair[] p, int el, int[] b) {\n\n\t\tint l = 0, h = p.length - 1,  i = -1;\n\n\t\twhile (l <= h) {\n\n\t\t\tint mid = (l + h) / 2;\n\n\t\t\tif (p[mid].p <= el) {\n\t\t\t\ti = mid;\n\t\t\t\tl = mid + 1;\n\t\t\t} else\n\t\t\t\th = mid - 1;\n\t\t}\n\n\t\tif (i == -1) return 0;\n\t\t\n\t\treturn b[i];\n\t}\n}\n```\n
['Array', 'Sorting', 'Binary Tree', 'Java']