Download presentation
Presentation is loading. Please wait.
Published byLee Warren Modified over 8 years ago
1
Technical Interviews Shane Carr CSE 232, September 11, 2015
2
Letter Counter: Language Breakdown
3
Letter Counter: Approach to Sorting
4
Schedule for the next few weeks In Lecture Today Interview Techniques Time Complexity Preview of Problem Analysis Next Week Problem Analysis Data Structures Next-Next Week Start on algorithms Programming Contests This Weekend: HackerRank CodeSprint! https://www.hackerrank.c om/worldcup/ https://www.hackerrank.c om/worldcup/ Sign up by next Wednesday at midnight : ICPC Qualifiers! https://docs.google.com/ forms/d/1J006- xI3G9sN0yfHaZifZ8wkzZt5f5 9Oyv4n5uOgTXI/viewform https://docs.google.com/ forms/d/1J006- xI3G9sN0yfHaZifZ8wkzZt5f5 9Oyv4n5uOgTXI/viewform
5
First: A Few More Tips For functional-style programming
6
Python: Comprehension Syntaxes All the major data structures are supported: Iterator (most common) List (like Iterator, but stores result in memory) Set (stores unique values) Dictionary (stores a key- value association) All of them support mapping and filtering. myIter = (x.lower() for x in src) myList = [x.lower() for x in src] mySet = {x.lower() for x in src} myDict = {x.lower(): "hi" for x in src}
7
Java: More Stream Shortcuts Get the sum of the int[] array src int sum = IntStream.of(src).sum(); Perform a map with ternary syntax on the List grades Stream strm = grades.stream().map(x -> (x > 65) ? "P" : "F"); Count how many items of a List strs have at least 5 chars int n = strs.stream().filter(x -> x.length()>5).count();
8
C++11: Lambda Functions For example, to square an std::vector containing ints: std::transform( vec.begin(), vec.end(), vec.begin(), [](int i){ return i*i; } ); In order to confuse people, the C++ folks changed the names of the common functional operations. Map is called “std:: transform ” Filter is called “std:: remove_if ” Reduce is called “std:: accumulate ” Source Start Source End Destination Start Lambda Function
9
Swiss Army Knives for String Parsing and Formatting Regular Expressions A syntax for parsing an arbitrary string format Regex syntax is standard in most, but not all, languages # Python import re re.match(r"\w+", str) // Java str.matches("\\w+") Printf A syntax for formatting output strings Printf syntax is standard in most, but not all, languages # Python print("%s = %6.4f" % ("pi", math.pi)) // Java System.out.format("%s = %6.4f", "pi", Math.PI);
10
Time Complexity Review Based on Gayle Laakmann McDowell’s Cracking the Coding Interview, 6 th Edition Chapter VI
11
Sort these from slow to fast. You don’t need to know Master Method for most interviews, but you’ve gotta know this! Choices O(n 2 ) (aka Quadratic) O(n) (aka Linear) O(n log n) O(2 n ) O(1) (aka Constant) O(n!) O(log n) Solution O(n!) O(2 n ) O(n 2 ) O(n log n) O(n) O(log n) O(1) If you have no clue about what’s on this slide, take CSE 241.
12
CtCI Chapter VI Solutions 1.O(b) 2.O(b) 3.O(1) 4.O(a/b) 5.O(log n) 6.O(sqrt n) 7.O(n) 8.O(n) 9.O(n 2 ) 10.O(log n) 11.O(kc k ) 12.O(b log b + a log b)
13
Technical Interviews Based on Gayle Laakmann McDowell’s Cracking the Coding Interview, 6 th Edition Chapters I and VII
14
Interviews are a standardized method for companies to estimate how good of an engineer you would be. The kinds of questions you solve in a technical interview are not necessarily the kind that you will actually solve at work. They hope that there is a correlation between being able to solve interview questions and being a good engineer.
15
Technical Interview Problem Solving Procedure 1)Listen Carefully to the problem statement 2)Draw an example on the whiteboard 3)State the Brute Force solution 4)Discuss Time Complexity 5)Try coming up with an optimized solution 6)Implement your solution on the whiteboard 7)Test your solution
16
Whiteboard Language Ask your interviewer if they have a preferred language. If they don’t, ask them if you can use your choice language. Potential Issues C++: make sure you don’t leak memory Java: to avoid writing too much, ask your interviewer if you can use shortcut syntax Python: make sure to check types, or at least tell your interviewer verbally that you would check types I’ve had some interviews where the interviewer was super picky about language and style, and others where the interviewer didn’t care.
17
Tips for Success These are mine, not from the book. NNever Ever let the interviewer get bored TThey’re a human just like you and me. IIf they lose interest or can’t follow what you’re doing, that’s a recipe for bad marks. TThink Out Loud!!! TThe interviewer can’t read your mind. IIf the room is quiet for 30 seconds or more, say what’s on your mind. BBe Confident YYou know more than you think.
18
How do you come up with the optimal solution? The Million-Dollar Question
19
Five Strategies Based on those in CtCI and CP3 Brute Force and Fix Base Case and Build Simplify and Generalize Reduce and Relate Do It Yourself
20
Brute Force and Fix Given a brute force solution, identify the following parts and fix them. 1. Bottlenecks: Focus on improving the slowest step. Improving a faster step won’t improve your algorithm’s overall time complexity. 2. Unnecessary Work: Reduce your search space. Are there cases you’re testing that are redundant? 3. Duplicated Work: Eliminate repeated sub- computations. Think Fibonacci.
21
Example 1 Given an array of distinct integer values, count the number of pairs of integers that have difference k. For example, given the array {1, 7, 5, 9, 2, 12, 3} and the difference k=2, you would find the pairs (1,3), (3,5), (5,7), and (7,9).
22
Example 2 Print all positive integer solutions to the equation a 3 + b 3 = c 3 + d 3 subject to the constraints 0 < a < b < 1000 0 < c < d < 1000 a < c
23
Example 3 You want to set up an irrigation system for your garden outside. In order to have enough sprinklers, you bought n hose splitters at the hardware store. Each splitter is binary: it takes an inlet stream and produces two outlet streams. In how many different configurations can you arrange them?
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.