E09: isUnique (Cracking the Coding Interview, Problem 1)

Cracking the Coding Interview (CTCI) is widely regarded as a preeminent resource to prepare for modern software development position interviews at leading high tech companies.

The goal of this experience is to continue to get familiar with writing very simple Typescript code using TypeScript Playground, and to get you acquainted with the “Workout of the Day” (WOD) pedagogical technique used in this course.

To do this, you will solve the very first problem in CTCI, called “isUnique”:

1.1. Is Unique: Implement an algorithm to determine if a string has all unique characters.

For example:

console.log(isUnique('abcde'));  // prints true
console.log(isUnique('abcdea')); // prints false

Prelude

You should probably have finished the previous practice WOD.

Review the first few sections of the ZE Javascript/Typescript Style Guide. For example, be sure to use let and const, not var.

Next, open TypeScript Playground. You may need to delete the existing code in the Playground.

The WOD

For this practice WOD, implement a Typescript function called isUnique, which accepts a string and returns true if the string has all unique characters, false otherwise (i.e. if it contains any duplicates).

Ready? Let’s begin:

  1. Start your timer.

  2. Create a Typescript function called “isUnique”. The function should compute and return the answer. Print the results out to the console.

  3. Informally test your program by running it and inspecting the output.

  4. Press the “Share” button to create a URL to refer to your code.

  5. Stop your timer and record your time. Be sure to record the times associated with all of your attempts at this WOD, because you will need your WOD time data when you write your technical essay.

Rx: < 7 min Av: 7-10 min Sd: 10-12 min DNF: 12+ min             

Demonstration

Once you’ve finished trying the WOD for the first time, watch me do it:

Standard WOD Caveats

You’ll learn significantly less from watching me solve the if you haven’t attempted the WOD yourself first.

While it’s an achievement to finish the WOD no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it is usually strategic to stop working at the DNF time and watch my solution.

After watching my solution, I recommend that you repeat the WOD if you have not achieved at least Av performance. If so, be sure to:

Feel free to keep trying until you make Rx if that’s of interest to you.

Submission Instructions

By the time and date indicated on the Schedule page, submit this assignment via Laulima.

Your submission should contain:

You will receive full credit for this practice WOD as long as you have attempted it at least once and submitted your work on Laulima with all required data before the due date. Your code does not have to run perfectly for you to receive full credit.