Skip to content

Instantly share code, notes, and snippets.

@ramyatata
ramyatata / Kth Smallest Element in a BST
Created March 10, 2018 18:14
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.
var kthSmallest = function(root, k) {
//input is tree
//output is value of node
//k value is always less than or equal to no.of nodes of tree
//space = linear and time =
//sort array in ascending order using tree traversal in to array
// storage for array
//pick k-1 th element
//pascal's triangle
var pascals = function(number) {
var initial = [[1], [1, 1]];
if (number === 0) {return []};
if (number === 1) {return [initial[0]]};
if (number === 2) {return initial};
var count = 2;
var recurse = function() {
if (count === number) {
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html