Last active
December 17, 2019 15:52
-
-
Save zakirsajib/630ef3613049928d52f5d1391100b5a0 to your computer and use it in GitHub Desktop.
Repeated String
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
<?php | |
// Complete the repeatedString function below. | |
function repeatedString($s, $n) { | |
$find_a = substr_count($s, "a"); | |
if($find_a > 1 && $n < 100000000000){ | |
$total_repeated_string = str_repeat($s, $n); | |
$actual_string = substr($total_repeated_string, 0, $n); | |
$string_length = strlen($actual_string); | |
$total_count = substr_count($actual_string,"a", 0, $string_length); | |
return $total_count; | |
}elseif($find_a == 0){ | |
return 0; | |
}elseif($find_a > 2 && $n > 100000000000){ | |
$total_count = $n * $find_a; | |
$total_count= substr($total_count, 0, -2); | |
return $total_count; | |
}elseif($find_a == 1 && (strlen($s)> 0 && strlen($s) < 2)) { | |
return $n; | |
}elseif($find_a == 1 && strlen($s)> 0) { | |
$total_count = round($n/strlen($s)); | |
return $total_count; | |
}elseif($find_a == 2 && strlen($s)> 0) { | |
$total_count = ceil($n/strlen($s)*$find_a); | |
return $total_count; | |
//}elseif($find_a > 2 && strlen($s)> 0 && $n > 500000000000) { | |
// $total_count = ceil($n*$find_a); | |
// return $total_count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Input
aba
10
Sample Output
7
Explanation
The first
n= 10
letters of the infinite string areabaabaabaa.
Because there are 7a
's, we print on a new line.Second Test case
Sample Input 1
a
1000000000000
Sample Output 1
1000000000000
Explanation 1
Because all of the first
n =1000000000000
letters of the infinite string are
a
, we print1000000000000
on a new line.