5/24/23, 7:46 PM Technical Coding Challenges Test on 24-May-23: Attempt review
Started on Wednesday, 24 May 2023, 7:02 PM
State Finished
Completed on Wednesday, 24 May 2023, 7:44 PM
Time taken 42 mins 9 secs
Marks 2.85/3.00
Grade 9.50 out of 10.00 (95%)
https://lms.mlrit.ac.in/mod/quiz/review.php?attempt=45501&cmid=13312 1/7
, 5/24/23, 7:46 PM Technical Coding Challenges Test on 24-May-23: Attempt review
Question 1
Correct
Mark 1.00 out of 1.00
You are given a string s. You can apply this operation to the string exactly once: choose index I and move character s[i] to the beginning of the
string (removing it at the old position). For example, if you apply the operation with index i=4 to the string "abaacd" with numbering from 1,
you get the string "aabacd". What is the lexicographically minimal string you can obtain by this operation?
A string a is lexicographically smaller than a string b of the same length if and only if the following holds: in the first position where a and b
differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
For example:
Test Input Result
Test case 1 3 acb
cba
Test case 2 4 aacc
acac
Answer: (penalty regime: 5, 10, ... %)
1 ▼ import java.util.*;
2 public class Prog
3 ▼ {
4 public static void main(String[] args)
5 ▼ {
6 Scanner scr=new Scanner(System.in);
7 int n=scr.nextInt();
8 String s=scr.next();
9 char m='~';
10 for(int i=0;i<n;i++)
11 ▼ {
12 char c=s.charAt(i);
13 if(c<m)
14 ▼ {
15 m=c;
16 }
17 }
18 String ans="";
19 for(int i=0;i<n;i++)
20 ▼ {
21 char c=s.charAt(i);
22 if(c==m)
23 ▼ {
24 ans=c+ans;
25 }
26 else
27 ▼ {
28 ans=ans+c;
29 }
30 }
31 System.out.println(ans);
32 }
33 }
Test Input Expected Got
Test case 1 3 acb acb
cba
Test case 2 4 aacc aacc
acac
Passed all tests!
Correct
https://lms.mlrit.ac.in/mod/quiz/review.php?attempt=45501&cmid=13312 2/7
Started on Wednesday, 24 May 2023, 7:02 PM
State Finished
Completed on Wednesday, 24 May 2023, 7:44 PM
Time taken 42 mins 9 secs
Marks 2.85/3.00
Grade 9.50 out of 10.00 (95%)
https://lms.mlrit.ac.in/mod/quiz/review.php?attempt=45501&cmid=13312 1/7
, 5/24/23, 7:46 PM Technical Coding Challenges Test on 24-May-23: Attempt review
Question 1
Correct
Mark 1.00 out of 1.00
You are given a string s. You can apply this operation to the string exactly once: choose index I and move character s[i] to the beginning of the
string (removing it at the old position). For example, if you apply the operation with index i=4 to the string "abaacd" with numbering from 1,
you get the string "aabacd". What is the lexicographically minimal string you can obtain by this operation?
A string a is lexicographically smaller than a string b of the same length if and only if the following holds: in the first position where a and b
differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
For example:
Test Input Result
Test case 1 3 acb
cba
Test case 2 4 aacc
acac
Answer: (penalty regime: 5, 10, ... %)
1 ▼ import java.util.*;
2 public class Prog
3 ▼ {
4 public static void main(String[] args)
5 ▼ {
6 Scanner scr=new Scanner(System.in);
7 int n=scr.nextInt();
8 String s=scr.next();
9 char m='~';
10 for(int i=0;i<n;i++)
11 ▼ {
12 char c=s.charAt(i);
13 if(c<m)
14 ▼ {
15 m=c;
16 }
17 }
18 String ans="";
19 for(int i=0;i<n;i++)
20 ▼ {
21 char c=s.charAt(i);
22 if(c==m)
23 ▼ {
24 ans=c+ans;
25 }
26 else
27 ▼ {
28 ans=ans+c;
29 }
30 }
31 System.out.println(ans);
32 }
33 }
Test Input Expected Got
Test case 1 3 acb acb
cba
Test case 2 4 aacc aacc
acac
Passed all tests!
Correct
https://lms.mlrit.ac.in/mod/quiz/review.php?attempt=45501&cmid=13312 2/7