FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coderbyte-solution-JS/MinWindowSubstring.js at main · Ajit24/Coderbyte-solution-JS · GitHub
Ajit24
/
Coderbyte-solution-JS
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
10
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coderbyte-solution-JS
/
MinWindowSubstring.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (27 loc) · 918 Bytes
Breadcrumbs
Coderbyte-solution-JS
/
MinWindowSubstring.js
Copy path
File metadata and controls
34 lines (27 loc) · 918 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
function
MinWindowSubstring
(
arr
)
{
var
str1
=
arr
[
0
]
,
str2
=
arr
[
1
]
,
min
=
Infinity
,
output
;
for
(
var
i
=
0
;
i
<
str1
.
length
;
i
++
)
{
for
(
var
j
=
i
+
1
;
j
<=
str1
.
length
;
j
++
)
{
var
slice
=
str1
.
slice
(
i
,
j
)
;
if
(
slice
.
length
<
min
&&
scramble
(
slice
,
str2
)
)
{
output
=
slice
;
min
=
slice
.
length
;
}
}
}
return
output
;
}
function
scramble
(
str1
,
str2
)
{
function
obj
(
str
)
{
return
str
.
split
(
""
)
.
reduce
(
function
(
prev
,
curr
)
{
prev
[
curr
]
?
prev
[
curr
]
++
:
prev
[
curr
]
=
1
;
return
prev
;
}
,
{
}
)
;
}
var
charCount1
=
obj
(
str1
)
,
charCount2
=
obj
(
str2
)
;
return
Object
.
keys
(
charCount2
)
.
reduce
(
function
(
prev
,
curr
)
{
return
Math
.
min
(
prev
,
charCount1
[
curr
]
/
charCount2
[
curr
]
||
0
)
;
}
,
Infinity
)
>=
1
;
}
// keep this function call here
MinWindowSubstring
(
readline
(
)
)
;
Back
|
FazBrowse Home
|
New Git URL