-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5042fb4
commit 2e8f603
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//{ Driver Code Starts | ||
// Initial Template for Java | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class GFG { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); | ||
int t = Integer.parseInt(read.readLine()); | ||
while (t-- > 0) { | ||
Long X = Long.parseLong(read.readLine()); | ||
|
||
Solution ob = new Solution(); | ||
System.out.println(ob.reversedBits(X)); | ||
} | ||
} | ||
} | ||
// } Driver Code Ends | ||
|
||
|
||
// User function Template for Java | ||
|
||
class Solution | ||
{ | ||
static Long reversedBits(Long x) | ||
{ | ||
// code here | ||
StringBuilder sb=new StringBuilder(""); | ||
while(x>0) | ||
{ | ||
sb.append((char)(x%2+48)); | ||
x=x/2; | ||
} | ||
|
||
int n=32-sb.length(); | ||
|
||
for(int i=0;i<n;i++) | ||
sb.append((char)(48)); | ||
|
||
return Long.parseLong(sb.toString(),2); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(logx) | ||
Space complexity - O(1) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(m*n) | ||
Space complexity - O(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class Solution | ||
{ | ||
public int maximalRectangle(char[][] matrix) | ||
{ | ||
if (matrix.length == 0) | ||
return 0; | ||
|
||
int ans = 0; | ||
int[] hist = new int[matrix[0].length]; | ||
|
||
for (char[] row : matrix) | ||
{ | ||
for (int i = 0; i < row.length; ++i) | ||
hist[i] = row[i] == '0' ? 0 : hist[i] + 1; | ||
|
||
ans = Math.max(ans, largestRectangleArea(hist)); | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
private int largestRectangleArea(int[] heights) | ||
{ | ||
int ans = 0; | ||
Deque<Integer> stack = new ArrayDeque<>(); | ||
|
||
for (int i = 0; i <= heights.length; ++i) | ||
{ | ||
while (!stack.isEmpty() && (i == heights.length || heights[stack.peek()] > heights[i])) | ||
{ | ||
int h = heights[stack.pop()]; | ||
int w = stack.isEmpty() ? i : i - stack.peek() - 1; | ||
ans = Math.max(ans, h * w); | ||
} | ||
|
||
stack.push(i); | ||
} | ||
|
||
return ans; | ||
} | ||
} |