genaral-programming.hashnode.dev3644. Maximum K to Sort a Permutationclass Solution { public int sortPermutation(int[] nums) { int n = nums.length; int max = 1; while(max < n){ max<<=1; } max-=1; int k = max; for(int i=0; i<n; i++){ if...Aug 14, 2025·1 min read
genaral-programming.hashnode.dev228. Summary Rangesclass Solution { public List<String> summaryRanges(int[] nums) { List<String> result = new ArrayList<>(); if(nums.length == 0){ return result; } for(int i=0; i<nums.length; i++){ int start ...Aug 14, 2025·1 min read
searchinsert.hashnode.dev1021. Remove Outermost Parenthesesclass Solution { public String removeOuterParentheses(String s) { StringBuilder result = new StringBuilder(); int depth = 0; for (char c : s.toCharArray()) { if (c == '(') { if (depth > 0) { ...Aug 7, 2025·1 min read
searchinsert.hashnode.dev1021. remove-outermost-parenthesesclass Solution { public String removeOuterParentheses(String s) { StringBuilder result = new StringBuilder(); int depth = 0; for (char c : s.toCharArray()) { if (c == '(') { if (depth > 0) { ...Aug 7, 2025·1 min read
searchinsert.hashnode.dev84. Largest Rectangle in Histogramclass Solution { public int largestRectangleArea(int[] heights) { Stack<Integer> st = new Stack<>(); int res = 0; for(int i=0; i<heights.length; i++){ while(!st.isEmpty() && heights[st.peek()] >= heights[i]){ ...Aug 7, 2025·1 min read