Last active
July 16, 2024 02:07
-
-
Save subrotoice/f2d1957f86dc51e85793fe9d6275705c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Task 1: | |
function palindrome(input) { | |
var length = input.length; | |
if (length == 1) return true; | |
if (input[0] != input[length - 1]) return false; | |
var subStr = input.slice(1, length - 1); | |
return palindrome(subStr); | |
} | |
console.log(palindrome("madam")); | |
Time complexity: O(n/2) = O(n) | |
Space complexity: O(1) | |
Task 2: | |
function add(a, b) { | |
if (a === 1) return b; | |
return b + add(a - 1, b); | |
} | |
console.log(add(4, 5)); | |
Time complexity: O(n) | |
Space complexity: O(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment