This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Readfile(filename, sizefinder) { | |
console.log('Reading file.....'); | |
sizefinder(); | |
} | |
function sizefinder() { | |
console.log('File size is 32mb'); | |
} | |
Readfile('sampletxt', sizefinder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Reverse(samparr, begin, end) { | |
while (begin < end) { | |
temp = samparr[begin]; | |
samparr[begin] = samparr[end]; | |
samparr[end] = temp; | |
begin = begin + 1; | |
end = end - 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Rotate(samparr, d, n) { | |
if (d == 0) { | |
return; | |
} | |
Reverse(samparr, 0, d - 1); | |
Reverse(samparr, d, n - 1); | |
Reverse(samparr, 0, n - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let us have an array of n = 3 and d = 4 | |
let samparr = [1,2,3]; | |
// step 1 -> reverse d elements. | |
let samparr = ["out of bounds"] | |
// To resolve this we refactor d as d = d % n, | |
// so d becomes 1 and 1<n so we rotate the array with d as 1. | |
let samparr = [1,2,3]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Reverse(samparr, begin, end) { | |
while (begin < end) { | |
temp = samparr[begin]; | |
samparr[begin] = samparr[end]; | |
samparr[end] = temp; | |
begin = begin + 1; | |
end = end - 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample array | |
let samparr = [1,2,3,4,5]; | |
// step 1 -> reverse d elements. | |
let samparr = [2,1,3,4,5]; | |
// step 2 -> reverse n-d elements. Here n=5 and d=2 so (n-d) = (5-2=3) | |
let samparr = [2,1,5,4,3]; | |
// step 3 -> reverse n elements. This gives the rotated array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inpstring = "abc"; | |
let n = inpstring.length; | |
function FindSubstring(Str, n){ | |
for(let i=0; i<n ;i++){ | |
for(let j=i;j<n;j++){ | |
for(let k=i;k<j+1;k++){ | |
console.log(Str.charAt(k)) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inpstring = "abc"; | |
let n = inpstring.length; | |
function FindSubstring(Str, n){ | |
for(let i=0; i<n ;i++){ | |
for(let j=i;j<n;j++){ | |
// another for loop comes here | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inpstring = "abc"; | |
let n = inpstring.length; | |
function FindSubstring(Str, n){ | |
for(let i=0; i<n ;i++){ | |
// We are going to have two more loops here | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialising input string | |
let inpstring = "Hello"; | |
// length of the input string | |
let n = inpstring.length; |
NewerOlder