Code Monkey home page Code Monkey logo

ctci-6th-edition-javascript's Introduction

Cracking the Coding Interview 6th Edition - JavaScript

Instructions

  • This repository contains JavaScript attempts on questions listed in the book.

  • So far, code or short writeups are available for the first 10 chapters.

  • At Gayle's request, the files only contain code, and do not contain the actual questions. For the questions, please support Gayle by purchasing the book.

  • Under each JavaScript file, there are tests to check that the code is working as expected. For convenience, simple logging is used to test the functions. To run the tests, just cd into the folder containing the .js file and run node <fileName>.js to run the tests.

  • Contributions welcome

List of Coding Questions:

Chapter 1

  • 1.1 - Is Unique
  • 1.2 - Check Permutation
  • 1.3 - URLify
  • 1.4 - Palindrome Permutation
  • 1.5 - One Away
  • 1.6 - String Compression
  • 1.7 - Rotate Matrix
  • 1.8 - Zero Matrix
  • 1.9 - String Rotation

Chapter 2

  • 2.1 - Remove Dups
  • 2.2 - Return Kth to Last
  • 2.3 - Delete Middle Node
  • 2.4 - Partition
  • 2.5 - Sum Lists
  • 2.6 - Palindrome
  • 2.7 - Intersection
  • 2.8 - Loop Detection

Chapter 3

  • 3.1 - Three in One
  • 3.2 - Stack Min
  • 3.3 - Stack of Plates
  • 3.4 - Queue via Stacks
  • 3.5 - Sort Stack
  • 3.6 - Animal Shelter

Chapter 4

  • 4.1 - Route Between Nodes
  • 4.2 - Minimal Tree
  • 4.3 - List of Depths
  • 4.4 - Check Balanced
  • 4.5 - Validate BST
  • 4.6 - Successor
  • 4.7 - Build Order
  • 4.8 - First Common Ancestor
  • 4.9 - BST Sequences
  • 4.10 - Check Subtree
  • 4.11 - Random Node
  • 4.12 - Paths with Sum

Chapter 5

  • 5.1 - Insertion
  • 5.2 - Binary to String
  • 5.3 - Flip Bit To Win
  • 5.4 - Next Number
  • 5.5 - Debugger
  • 5.6 - Conversion
  • 5.7 - Pairwise Swap
  • 5.8 - Draw Line

Chapter 6

  • 6.1 - Heavy Pill
  • 6.2 - Basketball
  • 6.3 - Dominos
  • 6.4 - Ants on a Triangle
  • 6.5 - Jugs of Water
  • 6.6 - Blue-Eyed Island
  • 6.7 - The Apocalypse
  • 6.8 - The Egg Drop Problem
  • 6.9 - 100 Lockers
  • 6.10 - Poison

Chapter 7

  • 7.1 - Deck of Cards
  • 7.2 - Call Center
  • 7.3 - Jukebox
  • 7.4 - Parking Lot
  • 7.5 - Online Book Reader
  • 7.6 - Jigsaw
  • 7.7 - Chat Server
  • 7.8 - Othello
  • 7.9 - Circular Array
  • 7.10 - Minesweeper
  • 7.11 - File System
  • 7.12 - Hash Table

Chapter 8

  • 8.1 - Triple Step
  • 8.2 - Robot in a Grid
  • 8.3 - Magic Index
  • 8.4 - Power Set
  • 8.5 - Recursive Multiply
  • 8.6 - Towers of Hanoi
  • 8.7 - Permutations without Dups
  • 8.8 - Permutations with Dups
  • 8.9 - Parens
  • 8.10 - Paint Fill
  • 8.11 - Coins
  • 8.12 - Eight Queens
  • 8.13 - Stack Boxes
  • 8.14 - Boolean Eval

Chapter 9

  • 9.1 - Stock Data
  • 9.2 - Social Network
  • 9.3 - Web Crawler
  • 9.4 - Duplicate URLs
  • 9.5 - Cache
  • 9.6 - Sales Rank
  • 9.7 - Personal Financial Manager
  • 9.8 - Paste Bin

Chapter 10

  • 10.1 - Sorted Merge
  • 10.2 - Group Anagrams
  • 10.3 - Search In Rotated Array
  • 10.4 - Sorted Search No Size
  • 10.5 - Sparse Search
  • 10.6 - Sort Big File
  • 10.7 - Missing Int
  • 10.8 - Find Duplicates
  • 10.9 - Sorted Matrix Search
  • 10.10 - Rank From Stream
  • 10.11 - Peaks And Valleys

Test

npm test

ctci-6th-edition-javascript's People

Contributors

asaph avatar bialesdaniel avatar charitymarani avatar chengjieyun59 avatar chrismilson avatar dawsbot avatar dependabot[bot] avatar greencarlos avatar kapilraghuwanshi avatar kloncentaur8 avatar lopezpdvn avatar mvivekc avatar profnandaa avatar rajasimhared avatar raziyehbazargan avatar sea-witch avatar varunm1813 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ctci-6th-edition-javascript's Issues

Update ch1-q1?

Would it make sense to change the params for the solutions to take a string rather than an array? I was thrown off by the use of sort in the second solution until I realized the "str" variable was actually an array.

The problem in the book clearly requests an implementation of an algorithm that works on a string. I suppose this is something the candidate could/should check before hand so I can understand reasoning for leaving it in.

Mismatch in question 2.8 (loop detection in linked list)

The Problem:
The answer to question 2.8 is incomplete.

The code in these answers seems to only return true or false as to whether there is a loop in the linked list, instead of the node at the start of the loop.

The Solution:
I could set up a pull request for this.

Add new contributor & remove me

Would love to see someone else take this over. It's not worth it for me currently to devote time or effort to work on this.

All the best ✌️❤️

My variant of the Urlify problem.

function urlify(str, length) {
var arr = str.trim().split('');

arr.forEach((item, i) => {
if ( item === ' ' ) arr[i] = '%20';
});

return arr.join('');
};

Test with CI

Travis or Circle. Would be awesome for linting and unit testing both. Both options are free for open-source software and provide a much higher code quality for PR's.

Need to add "dawsonbotsford" to the CarreerCup org as a person by @gaylemcd or another stake-holder on the careercup GitHub group if I understand the permissions correctly.

chapter01/1.3 - URLify/urlify.js

For this problem, why wouldn't you do something along the lines of:

var uglify = function(input) {
  input = input.trim();
  var url = input.split(' ').join('%20');
  return url;
}

I know it says that it provides with the true length of the string, but would something a long these lines not be acceptable?

1.6 String Comparison Error

The provided solution assumes that any computed compressed string "compressed" will be shorter than the provided string "string" only if the maximum count for every input is 1. This is incorrect. Take the counterexample string "abcdd" (len:5). When compressed by the given solution, the proposed compressed string is given as "a1b1c1d2" (len:8). A better solution would be to simply compare the lengths of the given string before returning.

1.6 Length bug

The way that string length is compared and calculated is not correct when strings have significant entropy. See my branch showing this here @tankwan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.