ebook img

Daily Coding Problem: Get exceptionally good at coding interviews by solving one problem every day PDF

300 Pages·2019·8.395 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Daily Coding Problem: Get exceptionally good at coding interviews by solving one problem every day

Daily Coding Problem Alex Miller and Lawrence Wu 1 2 Copyright© 2019, Alex Miller and Lawrence Wu All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical means, including information storage and retrieval systems, without permission in writing from the publisher, except in the case of brief quota tions embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For more information, email the authors at founders@dailycoding problem.com. SECOND EDITION ISBN 978-1-7932966-3-4 ( ' Printed in the United States of America Cover Design by Irene Zou 10987654321 Alex: For Mom, Dad,Jordan, Hannah, and Zaddy Lawrence: For Mama and Papa 3 Contents Contents 5 I Data Structures 17 1 Arrays 19 1.1 Get product of all other elements . 20 1.2 Locate smallest window to be sorted 22 1.3 Calculate maximum subarray sum . 24 1.4 Find number of smaller elements to the right . 26 2 Strings 29 2.1 Find anagram indices 29 2.2 Generate palindrome pairs 32 2.3 Print zigzag form . . . . . 34 2.4 Determine smallest rotated string . 36 3 Linked Lists 41 3.1 Reverse linked list ............. . 42 3.2 Add two linked lists that represent numbers 44 3.3 Rearrange a linked list to alternate high-low 46 3.4 Find intersecting nodes of linked lists . 48 4 Stacks and Qyeues 51 4.1 Implement a max stack ......... . 53 4.2 Determine whether brackets are balanced 54 4.3 Compute maximum ofk-length subarrays 56 4.4 Reconstruct array using+/- signs ..... 59 5 Hash Tables 63 5. 1 Implement an LRU cache . 65 5.2 Cut brick wall ...... . 68 5 CONTENTS 6 5.3 Implement a sparse array 70 6 Trees 73 6.1 Count unival trees . 75 6.2 Reconstruct tree from pre-order and in-order traversals 79 6.3 Evaluate arithmetic tree . . . . . . 81 6.4 Get tree level with minimum sum 83 7 Binary Search Trees 85 7 .1 Find floor and ceiling . . . . . . 87 7.2 Convert sorted array to BST .. 88 7.3 Construct all BSTs with n nodes 90 8 Tries 93 8.1 Implement autocomplete system 95 8.2 Create PrefixMapSum class . . . 98 8.3 Find Maximum XOR of element pairs 102 9 Heaps 105 9 .1 Compute the running median 107 9 .2 Find most similar websites 109 9 .3 Generate regular numbers . 111 9.4 Build a Huffman tree 113 10 Graphs 119 10.1 Determine if a cycle exists . 122 10.2 Remove edges to create even trees 124 10.3 Create stepword chain .. 126 10.4 Beat Snakes and Ladders 128 10.5 Topological sort ... 130 11 Advanced Data Structures 133 11.1 Fenwick tree ..... 134 11.2 Disjoint-set data structure 137 11.3 Bloom filter . . . . . . . . 140 II Algorithms 143 12 Recursion 145 12.1 Tower of Hanoi ....... . 146 12.2 Implement regular expressions 149 12.3 Find array extremes efficiently 151 12.4 Play Nim . . . . . . . . . . . 154 CONTENTS 7 13 Dynamic Programming 157 13.1 Number of ways to climb a staircase 160 13.2 Number of ways to decode a string 162 13.3 Painting houses . . . . . . . . . . 164 14 Backtracking 167 14.1 Compute flight itinerary 169 14.2 Solve Sudoku ..... . 171 14.3 Count Android unlock combinations . 174 15 Sorting and Searching 179 15 .1 Dutch flag problem . . . . . . . 181 15 .2 Pancake sort . . . . . . . . . . . 183 15 .3 Efficiently sort a million integers 185 15 .4 Find minimum element in rotated sorted array . 186 16 Pathfinding 189 16.1 Dijkstra's algorithm 190 16.2 Bellman-Ford . 193 16.3 Floyd-Warshall 195 17 Bit Manipulation 199 17.1 Find element that appears once in list ....... . 201 17.2 Implement division without / or * operators . . . . . 202 17.3 Compute longest consecutive string of ones in binary 204 17.4 Find nth sevenish number .............. . 205 18 Randomized Algorithms 209 18.1 Pick random element from infinite stream 210 18.2 Shuffle deck of cards 212 18.3 Markov chain .. 215 19 Advanced Algorithms 219 19.1 Rabin-Karp ... 220 19.2 Hierholzer's algorithm 224 19.3 A* search ...... . 227 III Applications 235 20 Applications 237 20.1 Ghost ..... . 238 20.2 Connect 4 ... . 241 20.3 Cryptarithmetic . 247 CONTENTS 8 20.4 Cheapest itinerary . 251 20.5 Alien dictionary .. 254 20.6 Prime numbers .. 256 20.7 Crossword puzzles. 259 20. 8 UTF-8 encodings . 263 20.9 Blackjack ..... 265 IV Design 271 21 Data Structure Design 273 21.1 Dictionary with time key 274 21.2 Qyeue with fixed-length array 278 21.3 Qyack ............ . 282 22 System Design 287 22.1 Crawl Wikipedia .......... . 288 22.2 Design a hit counter . . . . . . . . . . 293 22.3 What happens when you visit a URL? 296 Glossary 299

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.