-
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
835b6f1
commit a7bac35
Showing
4 changed files
with
77 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,52 @@ | ||
//{ Driver Code Starts | ||
//Initial Template for Java | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
|
||
class GfG | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc = new Scanner(System.in); | ||
int t = sc.nextInt(); | ||
while(t-->0) | ||
{ | ||
String S = sc.next(); | ||
int R = sc.nextInt(); | ||
int N = sc.nextInt(); | ||
Solution obj = new Solution(); | ||
System.out.println(obj.nthCharacter(S,R,N)); | ||
} | ||
|
||
} | ||
} | ||
|
||
// } Driver Code Ends | ||
|
||
|
||
//User function Template for Java | ||
|
||
class Solution | ||
{ | ||
public char nthCharacter(String s, int r, int n) | ||
{ | ||
//code here | ||
while(r-- > 0) | ||
{ | ||
String m = ""; | ||
for(int i = 0; i < Math.min(s.length(),n+1); i++) | ||
{ | ||
if(s.charAt(i) == '1') | ||
m+="10"; | ||
else | ||
m+="01"; | ||
} | ||
|
||
s = m; | ||
} | ||
|
||
return s.charAt(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,2 @@ | ||
Time complexity - O(r * |s|) | ||
Space complexity - O(|s|) |
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(n) | ||
Space complexity - O(1) |
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,21 @@ | ||
class Solution | ||
{ | ||
public int getCommon(int[] nums1, int[] nums2) | ||
{ | ||
int i = 0; | ||
int j = 0; | ||
|
||
while (i < nums1.length && j < nums2.length) | ||
{ | ||
if (nums1[i] == nums2[j]) | ||
return nums1[i]; | ||
|
||
if (nums1[i] < nums2[j]) | ||
++i; | ||
else | ||
++j; | ||
} | ||
|
||
return -1; | ||
} | ||
} |