Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Coding challenges

Rating
-
Sold
-
Pages
7
Grade
A+
Uploaded on
22-08-2023
Written in
2023/2024

it contains coding challenges for practice

Institution
Course

Content preview

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

Written for

Course

Document information

Uploaded on
August 22, 2023
Number of pages
7
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$7.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
kondaharshitha11

Also available in package deal

Get to know the seller

Seller avatar
kondaharshitha11 Mlrit
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions