You are on page 1of 254
Programming Interviews. Exposed Secrets to Landing Your Next Job John Mongan Noah Suojanen Wiiey Computer NEW YORK + CHICHESTER + WEINHEIM + BRISBANE + SINGAPO! Publisher: Robert Ipsen Editor: Marjorie Spencer Assistant Editor: Margaret Flendrey Managing Editor: John Atkins Text Design & Composition: Publishers’ Design and Production Services, Inc. Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons, Inc, is aware of a claim, the ‘product names appear in initial capital or ALL CAPITAL LETTERS, Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. This book is printed on acidfee paper. © Copyright © 2000by John Mongan, Noah Suojanen. Allrights reserved. Pablished by Joha Wiley & Sons, In Published simultaneously in Canada, [No part of this publication may be reproduced, stored ina retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or othecwise, except as permitted under Sections 107 or 108 ofthe 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA{1923, (978) 750-8400, fax (978) 750- 4744, Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc, 605 Third Avenue, New York, NY 10158-0012, 212) '850-6011, fax (212) 850-6008, E-Mail: PERMREQ @ WILEY.COM. ‘This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. Its sold with the understanding that the publisher is not engaged in professional services. If professional advice or other expert assistance is required, the services of a competent professional person should be sought. Library of Congress Cataloging-in-Publication Data: ‘Mongan, John, 1976 ‘Programming interviews exposed : secrets to landing your next job / John Mongan, ‘Noa Sugjanen, Pp. cm. “Wiles computer publishing.” ISBN 0-471-88356-2 (pbk. : alk. paper) 1. Employment interviewing, 2. Computer programming—Vocational guidanee. 1. Suojanen, Noah, 1978-1, Tile HIFS549.516 Mob 2000 650.14 ded 00-028904 Printed in the United States of America, 10987654321 Preface Acknowledgments Chapter 1: Chapter 2: Chapter 5: The Job Application Process Contacting Companies Screening Interviews On-site Interviews Dress Recruiters Offers and Negotiation Accepting and Rejecting Offers Approaches to Programming Problems ‘The Process About the Questions Solving the Questions When You Get Stuck Analysis of the Solution Linked Lists Singly Linked Lists Modifying the Head Pointer ‘Traversing. Insertion and Deletion Contents eee De un u 13 “4 16 v7 23 24 25 26 27 Chapter 4: Chapter 5: Doubly Linked lists Circular Linked Lists ‘Problem: Stack Implementation Problem: Maintain Linked List Tail Pointer Problem: Bugs in Removetfead Problem: Mth-to-Last Element of a Linked List Problem: List Flattening Problem: Null Or Cycle ‘Trees and Graphs Trees Binary Trees Binary Search Trees Lookup Heaps ‘Common Searches Brendth-First Search Depth-First Search Traversals Graphs Problem: Preorder Traversal Problem: Preorder Traversal, No Recursion Problem: Lowest Common Ancestor Arrays and Strings Arrays C/C++ Java Perl Strings c CH Java Perl Problem: First Non-repeated Character Problem: Remove Specified Characters Problem: Reverse Words Problem: Integer/String Conversions Chapter 6: Chapter 7: Chapter 8: Chapter 9: Chapter 10: Recut Problem: Binary Search Problem: Permutations ofa String Problem: Combinations of a String Problem: Telephone Words Other Programming Topics Graphics Bit Operators Structured Query Language (SQL) Concurrency Probleme Eighth of a Circle Problem: Rectangle Overlap Problem: Big-endian or Little-endian Problem: Number of Ones Problem: Simple SQL Problem: Company and Employee Database Problem: Max, No Aggregates Problem: Praducer/Consumer Counting, Measuring, and Ordering Puzzles Problem: Count Open Lockers Problem: Three Switches Problem: Bridge Crossing Problem: Heavy Marble Graphical and Spatial Puzzles Problem: Boat and Dock Problem: Counting Cubes Problem: The Fox and Duck Problem: Burning Fuses Problem: Escaping the Train Knowledge-Based Questions Resumes The Questions Problem: C++ and Java 101 106 108 13 uz 125 125 az 129 132 135 137 ua us 8. 18. 150 182 159 164 166 167 wm 7 178 181 185 188 189 193 193 194 195 Contents Chapter 11: ‘Appendix: Index Problem: Including Files Problem: Storage Classes Problem: Friend Class Problem: Class and Struct Problem: Parent Class and Child Class Problem: Argument Passing Problem: Macros and tine Functions Problem: Inheritance Problem: Object-Oriented Programming Problem: Thread Programming Issues Problem: Garbage Collection Problem: 32-Bit Operating System Problem: Network Performance Problem: Faster Disk Access Problem: Database Advantages Problem: Cryptography Problem: New Cryptography Algorithms Problem: Hashtables and Binary Search Trees Non-Technical Questions The Questions (Question: What do you toant to do? Question: What is your favorite programming language? Question: What is your work style? Question: Tell me about your experience. Question: What are your career goals? Question: Why are you looking to change jobs? Question: How much money do you want to make? Question: What is your salary history? Questions: Why should we hire you? Question: Do you have arty questions for me? 196 196 197 197 198, 199 201 202 203 204 205 207 207 207 208 210 210 213 214 215 216 216 217 27 217 218 21 221 22 23 245 Preface If you're like us, you don’t usually read prefaces. This one has some use- ful information in it, though, so we hope you'll make an exception. If you're still going to skip the preface, here’s what you really need to know: You'll get as much out of this book as you put into it. If you read this book cover to cover, you'll leam something, but not nearly as much as you would if you take some time trying to work through the problems on your own before you read the answers, This book will help prepare you for the interviews you will face when seeking a job in programming, development, technical consulting, or any other field that warrants a programming interview. Programming inter- views bear little resemblance to those described in traditional job-hunting, and interview books. They consist almost entirely of programming prob- lems, puzzles, and technical questions about computers. We will discuss each of the kinds of problems you are likely to encounter and illustrate how they are best approached using questions from real interviews as, examples. ‘At this point you may be wondering who we are and what gives us the authority to write this book. We're both recent graduates who've been through a lot of interviews in the past few years. We've interviewed for jobs ranging from technical consulting with large established companies to writing device drivers for start-ups. This book is based on the experi- ences and observations we've taken from those interviews—what yielded offers and what didn’t. We believe that this is the best possible basis for a book like this. Rather than give you some HR exec’s idea of how inter- viewing should be done’ or a headhunter’s impression of how it might For the record, we don’t think that the way interviewing is done today is necessarily the way It should be done, The current mode puts too much emphasis on ablity to solve puzzles anc me Preface be done, we will tell you what interviews are really like at America’s top software and computer companies and what you need to do to get the job you want. To that end, we haven’t made up any of the questions in this book. Every last one of them has come from a recent interview. The distribu- tions of problem type and difficulty are similar to what you should expect to encounter in your interviews. We must emphasize that the problems presented in this book are a representative sample of the questions asked in interviews, not a comprehensive compilation. Reading this book straight through and memorizing the answers would completely miss the point. You may be asked some of the questions that appear in this book, but you should not expect that. A large and constantly changing body of questions is asked, and any intelligent interviewer who has seen this book will never again use any of the questions that appear here. On the other hand, interview questions encompass relatively few topic areas and types of questions, and these rarely change. If you work on learning to solve not just the specific problems we present, but the types of problems we pre~ sent, you'll be able to handle anything they throw at you in an interview. We've taken a couple of steps to facilitate the objective of improving your problem-solving skills. First, where appropriate, we provide reviews of important topics before we present questions on those topics. Second, instead of merely giving answers to the problems, we illustrate the prob- Jem-solving process from beginning to solution. We've found that most textbooks and nearly all puzzle books take a different approach to exam- ples: They begin with a problem, go immediately to the answer, and then explain why the answer is correct. In our experience, the result is that the reader may understand the particular answer and why it’s right, but is. left with no clue as to how the author came up with that solution or how a similar problem might be solved. We hope that our step-by-step approach to solutions will address this problem, helping you to under- stand not only the answers but how you get the answers. Learning by watching is never as effective as learning by doing. If you want to get the most out of this book, you will have to work out the prob- ems yourself. We suggest the following method. After you read a prob- Jem, put the book down and try to work out the solution. If you get stuck, start reading the solution. We never blurt out the answer at the beginning, 0 you don’t have to worry that we're going to give away the solution. Read just far enough to get the hint you need, then put down the book ‘nly with relay ited body of knowlege, anit general fil to measure a tof shesklle hat are cnc Wo succes in indus ena Smelly

You might also like