Skip to content

Instantly share code, notes, and snippets.

View bmelnychuk's full-sized avatar

Bogdan Melnychuk bmelnychuk

  • Hamburg, Germany
View GitHub Profile
@bmelnychuk
bmelnychuk / The Technical Interview Cheat Sheet.md
Created January 22, 2017 13:58 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
class Question {
id: string;
body: string;
answer: string;
}
interface AnswerValidationPolicy {
isAnswerValid(userAnswer: string, correctAnswer: string): Promise<boolean>;
}
interface NextQuestionPolicy {
getNextQuestion(availableQuestions: Question[]): Promise<Question>;
}
interface QuestionRepository {
getAvailableQuestions(categoryId: string): Promise<Question[]>;
getById(questionId: string): Promise<Question>;
}
...
export function getQuestions(categoryId: string): Promise<{ id: string, question: string, answer: string}[]>
export function getQuestion(questionId: string): Promise<{ id: string, question: string, answer: string}>
...
import { getQuestions, getQuestion } from '../../../question-store';
export default class QuestionStoreRepository implements QuestionRepository {
async getAvailableQuestions(categoryId: string): Promise<Question[]> {
const rawQuestions = await getQuestions(categoryId);
return rawQuestions.map(rawQuestion => new Question(
rawQuestion.id,
rawQuestion.question,
rawQuestion.answer
));
class RandomNextQuestionPolicy implements NextQuestionPolicy {
async getNextQuestion(availableQuestions: Question[]): Promise<Question> {
if (availableQuestions.length === 0)
throw new Error('Next question is not available');
const nextRandomIndex = RandomNextQuestionPolicy.getRandomInt(
0, availableQuestions.length - 1
);
return Promise.resolve(availableQuestions[nextRandomIndex]);
}
class TextEqualityAnswerValidationPolicy implements AnswerValidationPolicy {
isAnswerValid(userAnswer: string, correctAnswer: string): Promise<boolean> {
return Promise.resolve(
userAnswer.trim().toLowerCase() === correctAnswer.toLowerCase()
);
}
}
class AnswerResult {
userAnswer: string;
isValid: boolean;
correctAnswer: string;
}
class AnswerQuestion {
questionRepository: QuestionRepository;
answerValidationPolicy: AnswerValidationPolicy;