FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProgramming/HackerRank/ThirtySeven.java at patch-1 · subham500071430/JavaProgramming · GitHub
subham500071430
/
JavaProgramming
Public
forked from
karterhhgg/JavaProgramming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProgramming
/
HackerRank
/
ThirtySeven.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (29 loc) · 1004 Bytes
Breadcrumbs
JavaProgramming
/
HackerRank
/
ThirtySeven.java
Copy path
File metadata and controls
37 lines (29 loc) · 1004 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package
HackerRank
;
import
java
.
util
.
Scanner
;
public
class
ThirtySeven
{
public
static
String
getSmallestAndLargest
(
String
s
,
int
k
) {
String
smallest
=
s
.
substring
(
0
,
k
);
String
largest
=
s
.
substring
(
0
,
k
);
// Complete the function
// 'smallest' must be the lexicographically smallest substring of length 'k'
// 'largest' must be the lexicographically largest substring of length 'k'
for
(
int
i
=
1
;
i
<=
s
.
length
() -
k
;
i
++) {
String
substring
=
s
.
substring
(
i
,
i
+
k
);
if
(
substring
.
compareTo
(
smallest
) <
0
) {
smallest
=
substring
;
}
if
(
substring
.
compareTo
(
largest
) >
0
) {
largest
=
substring
;
}
}
return
smallest
+
"
\n
"
+
largest
;
}
public
static
void
main
(
String
[]
args
) {
Scanner
scan
=
new
Scanner
(
System
.
in
);
String
s
=
scan
.
next
();
int
k
=
scan
.
nextInt
();
scan
.
close
();
System
.
out
.
println
(
getSmallestAndLargest
(
s
,
k
));
}
}
}
Back
|
FazBrowse Home
|
New Git URL