Skip to content

Instantly share code, notes, and snippets.

@subrotoice
Last active July 16, 2024 02:07
Show Gist options
  • Save subrotoice/f2d1957f86dc51e85793fe9d6275705c to your computer and use it in GitHub Desktop.
Save subrotoice/f2d1957f86dc51e85793fe9d6275705c to your computer and use it in GitHub Desktop.
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