Skip to content

Commit

Permalink
Added codes for 9 March
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Mar 9, 2024
1 parent 835b6f1 commit a7bac35
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
52 changes: 52 additions & 0 deletions GeeksForGeeks/March/09-3-24/GFG.java
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);
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/March/09-3-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(r * |s|)
Space complexity - O(|s|)
2 changes: 2 additions & 0 deletions LeetCode/March/09-3-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
21 changes: 21 additions & 0 deletions LeetCode/March/09-3-24/Solution.java
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;
}
}

0 comments on commit a7bac35

Please sign in to comment.