Showing posts sorted by date for query quicksort. Sort by relevance Show all posts
Showing posts sorted by date for query quicksort. Sort by relevance Show all posts

Monday, April 25, 2022

Quick Select Algorithm

 

Quick Select Algorithm

Quick Select is a variation of the quicksort algorithm. It is an optimized way to find the kth smallest/largest element in an unsorted array.

Algorithm:

  • The partition part of the algorithm is same as that of quick sort.
  • After the partition function arranges the elements in list according to the pivot and returns the pivot_index, instead of recursing both sides of the pivot index, we recurse only for the part that contains our desired element

Time Complexity Analysis:

Worst case: Worst case occurs when we pick the largest/smallest element as pivot.

Thursday, March 10, 2022

Good advices: interview preparation

Here is the article.

Your ultimate guide to interview preparation

11 November 2018 

In this blog post I share my interview preparation process that helped me land offers from Google, Facebook, Uber and Amazon.

I describe how I prepared for different parts of the interview process, as well as share my philosophy on the interviews in general. Lastly, there are a lot of somewhat ad hoc links to some useful material throughout the article.

Text turned out to be pretty long, but reading it may be the easiest part of your preparation. So, get used :) Hope you will find it useful!

Table of Contents

  1. Premise
  2. Timeline
  3. Motivation
  4. Interview process
  5. Meta
  6. Books
  7. Coding interviews
  8. Distributed computing problems
  9. System design interviews
  10. Behavioral interviews
  11. Mock interviews
  12. Applying to companies
  13. Offers, negotiations and beyond
  14. Misc

Premise

Your interview experience may differ greatly depending on your background. Therefore, in order for you to find this guide more useful, I think it's necessary to share my background as it was at the time of applying.

First, I am a software engineer with more focus on the backend. Non-engineers have a completely different interview process. Frontend/ML/data/systems/mobile engineers have interviews which are fundamentally similar (after all, they also need to be able to code and know algorithms), but may have some parts that are specific to their role or otherwise different.

At the moment of writing, I live in the San Francisco Bay Area, part of which is often also called Silicon Valley. I applied only to the big and well-known tech companies, and all of them have offices here. Tech market is generally booming now, engineers are in high demand and well-paid, and it's pretty easy to find a job.

I am from Kazakhstan, and I am here in the United States on the work visa. Getting a work visa is hard, and this topic is well beyond this article (for a brief overview, read this piece), but the information here should generally work for most tech companies worldwide.

I have a bachelors degree in computer science from Nazarbayev University in Kazakhstan.

Before this round of applying to the companies, I had about 1.5 years of industry experience total. I was working for a smaller company ipsy, where I had a chance to work on a lot of cool tech stuff and got exposure to big systems at scale.

I have a lot of experience participating in programming contests, and my team got to the finals of ACM ICPC twice. So, I am pretty used to solving algorithmic problems, and before my interview preparation I generally already knew all the algorithms and data structures required to pass interview rounds.

I have a lot of friends in different big tech companies and startups. Their advice, help and experience definitely have been crucial to me. Thank you, guys! :)

Timeline

Before my onsite rounds, I intensively prepared for the interviews for about three months. On average, I worked on this about three hours a day, every day, so it's about 300 hours in total (I also worked fulltime during this time). In case you need to catch up on more or less material, you may need a different amount of time, but I think at least 200-400 hours during 2-4 months is a must first time you go through the hard interview process for a fulltime position.

Be also prepared that getting referrals, talking to recruiters, passing phone screens and onsite rounds, and getting and choosing offers will take some time, about 1-2 months. So you may want to plan accordingly and start contacting the companies earlier.

Motivation

Of course, investing at least three hours a day for several months into something is not easy, so here are some strategies that helped me:

  • Keep a log where you track how you prepare for interviews every day. I logged 98 days of my own preparation. Log not only helps you build a habit, it will also help later in reviewing the material you studied. For keeping a log I recommend Quiver - an Evernote alternative for programmers.
  • Read Deep work.
  • Quit social media.
  • Having a friend who is also preparing or passed interviews recently to discuss your progress with him/her definitely helps.
  • Make it your top priority. During my preparation, I didn't travel, rarely hung out with friends and ignored most of "important" errands.
  • Also, set yourself a deadline, something like "I will prepare for three months, and then apply". Not meeting a deadline is better than having no deadlines at all.
  • Read a chapter or two in Coders at Work for an inspiration.

Interview process

Good news: the interview process in most big tech companies is pretty similar, and you already may know all about it. But just to refresh your memory again, check out these materials on the format and structure of the interviews:

Meta

Some other guides and articles that I found useful:

Books

If you have time, I strongly recommend reading these books to get a deeper understanding of certain software engineering topics. I've read about 60% of their total content, full books in some cases and just several interesting chapters in others, and I feel it helped me a lot.

  • Effective Java – best book on Java, and I would recommend reading it even if you mostly use some other language.
  • Designing Data-Intensive Applications – a very good overview of the big distributed systems, and one of the best technical books I've ever read.
  • Clean Code – classic book on writing a good code.
  • Building Microservices – good book on microservices (without any unnecessary hype around them) that also provides a good overview of topics of security, testing, deployment and others.
  • Design Patterns by Gang of Four – classic book on design patterns. If you don't read all of it, make sure to at least know the following patterns: Singleton, Builder, Observer, Decorator, Facade.
  • Cracking the Coding Interview – I've read just several interesting chapters from there, but it's still a solid book about interview preparation in particular.
  • Modern Operating Systems – some chapters in this book provide a nice overview of hardware, memory management and other systems related concepts.
  • Learning PHP, MySQL & JavaScript – this book, which you can just skim in one evening, surprisingly provides a good overview of many important web concepts.
  • Coders at Work – book of motivating interviews with great programmers.

Coding interviews

Software engineer's interviews usually consist of coding, system design and behavioral rounds. Coding rounds, though, take at least 80% of the process, and by far are the most important. At these rounds you will typically get 1-2 algorithmic problems that you will need to solve in the language of your choice in about 45-60 minutes.

  • For practicing solving problems there is nothing better than Leetcode. It's so good that I feel anybody who solves 300-400 problems there will get a fair chance of clearing almost any interview round.
    • Leetcode has a lot of problems that are asked at the real interviews in big companies. By my estimations, about 25-30% of the problems I was asked to solve during the real interviews I solved on Leetcode before, and about 70% of the problems I was asked have something very similar there.
    • There is also a premium subscription for Leetcode that opens you more problems and features. I found it only somewhat helpful (mostly "problem frequency" feature and company problems lists), so it's up to you if you want to buy it or not. As another bonus, paying for the Leetcode subscription can be an additional motivation to solve it more ;)
    • Problem difficulties are not always very accurate, so don't skip easy problems. Hard problems, on the other hand, may be too tedious and intimidating, so get to them only once you are comfortable, and mix them with easier problems as well. Before my onsite rounds, I solved 333 Leetcode problems (115 easy, 160 medium, 58 hard), including ~100 that I solved several years before.
    • For choosing what to solve next, I recommend filtering problems by company tags (choose companies you want to apply to) and frequency. I also solved all problems from these collections and found them to be very helpful: top facebook questions, top google questions and top interview questions.
    • I participated in nine Leetcode contests and managed to reach 24th global rank before my onsites. Contests may be helpful to train your speed, but it's important to watch out for your solutions' code quality – you should write very clean code in your real interviews.
    • After solving the problem, be sure to check its discussion and some of the top solutions there. This will help you to learn about any better ways to solve the problem, and also you may find some good code examples for the language of your choice. Generally, at the interviews companies expect you to know at least one language very well, and write real code (not pseudocode) even on a whiteboard.
    • Avoid using IDEs and solve the problems right in the editor on the Leetcode website or on a whiteboard. This will better simulate a real interview environment.
  • Cracking the Coding Interview book has a nice collection of problems, though nowadays it's not as useful as Leetcode, where you can compile and test your solution. I mostly just checked the chapters I found interesting to me (for example, I recommend chapters about linked lists and trees).
  • During phone interviews you will code in some kind of a web editor while talking with the interviewer on a phone/skype, and on onsite interviews you mostly will code on the whiteboard. Writing a code on a whiteboard is pretty different from coding on the computer, therefore it's important to actually buy a whiteboard and solve more and more problems on it closer you get to the onsites. I got this one, and recommend getting at least this size or bigger.
  • This will probably be covered by 300-400 problems at Leetcode, but here is a list of algorithms and techniques you absolutely need to know: time and space complexity, sorting (quicksort, mergesort), binary search, hashmaps, trees, graphs, BFS/DFS, union find, tries, bit manipulation, stacks/queues, dynamic programming, priority queue, two pointers, recursion/backtracking, greedy solutions. Knowing this may also help: string hashing (Rabin-Karp algorithm), probability/combinatorics, segment tree, binary indexed tree (Fenwick Tree).
  • Note for those who are coming from competitive programming world: interview questions are a bit different than programming competitions problems. For example, in interview problems you may find restrictions that are pretty rare in CP world, like don't use division, don't use extra memory at all, or try solving the problem without using some particular algorithm. Also, code style expected in interviews is much cleaner and more structured than typical competitive programming code. Therefore even if you are pretty good with algorithms and solving competitive programming problems, I'd suggest still solving some Leetcode problems to get used to the format and prepare better.

    On the other hand, interview problems are much easier :)

Distributed computing problems

Some companies, especially Google, like to ask follow up problems that involve distributed computing – basically the same algorithmic problems, but you need to try to solve them using multiple cores/machines. I still don't know any good thorough source on this (ping me if you know?), but here is some material that I used for preparation:

  • Cormen has a nice chapter on parallel computing.
  • Some links that discuss certain distributed algorithm problems: 1, 2.
  • Learn about MapReduce paradigm and Spark framework.

System design interviews

In system design interviews, you are usually given a very vague design problem (like design Twitter), and you need to share your approach in about 45 minutes. The purpose of this interview is to test your experience working with real software systems, and how much you know about these systems in general. Usually, interns and new grads don't get this type of interviews, but otherwise you may expect it at every big tech company.

Here is a list of material you absolutely need to check:

Here are some videos that I found helpful:

I think one of the best ways to prepare for system design interviews is to expose yourself to as much information about designs of the real systems as possible, so here are lots of links to the blog posts, articles, videos and papers I found useful:

Behavioral interviews

In behavioral interviews, you will typically get asked questions like "What is the most challenging project you worked on?" or "What was your biggest failure during the time at the company X?", but this differs from company to company. At some companies, you may also get these questions asked during the usual coding interview rounds.

It's pretty hard to effectively prepare for this type of interview, but here are some guidelines and materials that will help:

Mock interviews

Real interviews are a pretty unique experience: you have to solve tough algorithmic problems in a limited time with somebody looking how you do it and with you explaining every step aloud. It may be confusing even if you are already a good coder, and this skill requires practice.

The best way to practice this without the risk of failing to get to the company of your dream is doing mock interviews. In these interviews you solve real interview problems in the setting as close to the real thing as possible. Here are the ways how you can do it:

  • Practice with friends. I did two mock interviews with friends and found both sessions very helpful. The downside of this approach is that you know your "interviewer" in advance, and, as a result, you are not as nervous as you may be on the real interview.
  • Pramp offers free mock interviews with peers, where you interview somebody over the internet for half an hour, and then they interview you. I did four mock interviews on the website, and found some of them to be pretty useful. On the downside, session quality heavily depends on your peer and the problem website chooses for you, and often the experience can be not that good. I also didn't really want to spend the time to interview people. During my time at ipsy I interviewed dozens of people, but if you never did this, I strongly suggest you trying Pramp – taking the side of the interviewer is a valuable experience.
  • For best mock interview experience, I strongly suggest gainlo.co. On this website, you arrange paid mock interviews with real engineers from Google, Facebook and other companies. Mock interviews are pretty expensive, but well worth it (partially because when you pay a lot of money for a mock interview, you treat it very seriously).
    I did four sessions: three with Googlers and one with Facebooker. Three interviews were coding ones, and one was system design. Mocks were awesome in three cases out of four, and these sessions really helped me to prepare better for the real interviews. One session, unfortunately, was quite mediocre.

Applying to companies

Applying to the companies is an art of its own. Remember that the whole interview process will take some time, so I suggest starting to reach out to the companies earlier. Here are some more additional points on this process:

  • Since preparing for the interviews is a big investment of your time and energy, it totally makes sense to apply to many companies at the same time. This way you have more chances that you will succeed, and with multiple offers at hand you can also negotiate a better compensation.
  • Best way to apply to the companies is through referrals from somebody who already works there. So reach out to your friends and friends of friends!
  • I solved all of Dropbox challenges at Codesignal (former Codefights), and within two weeks got contacted by 4-5 companies, including Twitter and Evernote. You may also try this.
  • Keep your LinkedIn updated. It is a good way to get contacted by the recruiters.
  • Don't stress out about resume too much. Read a chapter about resume in Cracking the Coding Interview, and check out this link on Careercup. Here is a Google Docs resume template that me and several of my friends successfully used to apply to the big tech companies – you can make a copy to create your own similar one! :)

You should also research the companies you apply to. Apart from Google and Wikipedia, here are some helpful links:

  • Glassdoor is a platform with employee reviews and other details for different companies.
  • Blind is an app and website where employees anonymously discuss their companies and a wide variety of other topics.

I also found that applying to the companies depends on your level of experience:

  • Students and new grads usually can apply only to internships and new grad positions respectively.
  • People with 3-5+ years of experience usually can easily get interviews almost anywhere.
  • Most of the positions require 3+ years of experience to apply for them, so with 1-2 years of experience (like in my case), the choice is somewhat limited and it may be harder to get interviews, especially with smaller companies.

Offers, negotiations and beyond

Here are some resources that will help you better navigate and negotiate different company offers. Remember that they want to hire you as much or even more as you want to get hired! :)

Misc

  • For phone screens make sure you have a reliable internet and phone connection, good headphones with a microphone, and a quiet place where you can be alone for the whole time. I also found that the best time for me to do phone screens is the first thing in the morning (after some breakfast of course). Interviews are a pretty nervous experience so you want to make yourself as comfortable and relaxed as you can.
  • Onsite interviews are physically and psychologically demanding, so you should take at least one rest day before and between them. I'd suggest taking something like one-two weeks off specifically to do onsites, and not doing more than three of them per week.

Saturday, July 11, 2020

Top 10 Algorithms for the Coding Interview (for software engineers)

Here is the link.

1. DFS 2. BFS 3. Matching Parenthesis problem 4. Using Hash Tables 5. Variables/Pointers manipulation 6. reverse linked list (duplicates , removing duplicates) 7. sorting fundamentals (quicksort, mergesort,bubblesort techniques , runtime of a sort,time space complexity) 8. Recursion 9. custom data structures (object oriented programming) 10.Binary search



Tuesday, July 31, 2018

Quick sort technique study

July 31, 2018

Introduction

It is time for me to review the algorithm using quicksort technique. Here is the gist.


Monday, March 27, 2017

45 minutes workout on a coding blog

March 27, 2017

Introduction


Julia did know the idea how to do a 45 minutes workout based on powerful search feature of Google. She searched her own blogs using keywords one by one, each one she spends 5 - 10 minutes to read.

Here is her tip to search.
Merge Sort, quicksort, hash function, tree, binary tree, binary search tree, stack, queue, BFS, graph, matrix.

Workout


Recursive function is here. 

Hash function is here. 

Actionable Items


Julia, you miss the heap, binary tree, non-sorted data structure, etc.  


Saturday, March 25, 2017

Code Review: Quicksort

March 25, 2017

Introduction

Sorting is the most important things in a programmer's life. Julia was so excited to know her first review of quicksort algorithm was chosen as the answer. But she has to keep up learning and makes a wise investment on learning quicksort.

Code review


Integer quicksort in Java



Tuesday, March 14, 2017

Algorithms to review

March 14, 2017

Code review 


Julia came cross the coding blog about algorithms today, when she reviewed the quicksort.

She likes to do some research on those algorithms in the blog.

Actionable items:


Read a competitive programmer blog - 23 algorithms
Study the blog - 23 algorithm talks - try to understand 1 -3 algorithms


Monday, March 13, 2017

Quick Search - Julia's first answer on code review

March 13, 2017

Julia got a big surprise today, her first day work on code review to answer a question on quick search was selected as the answer today, after more than 3 months, she noticed that she got 25 reputation.

The code review link is here. She has to celebrate a little bit, it was a long time she tried to find some activities to help others while she is struggling to invent herself, keep up with others in this computer science technology world.

Julia searched her blog using quicksort, and then she found somethings to review related to quicksort.

Make it more memorable, Julia uses an image and music to celebrate her good working spirit.


Jessica Simpson - Take my breath away

When  Julia read this news, she was so excited, take my breath away, a little exaggerated, reminded her a song - the old lovely song, feels good to help others and make her own mark. One step a time, ...

Actionable Items


1. Read all algorithms in the blog, the blogger got Google and Linkedin offer. The algorithms may be a good study material for Julia.

2. Review the C# implementation of quicksort, write a new one.


Thursday, November 24, 2016

Stack Exchange: Code Review - Julia's new school

Nov. 24, 2016

Julia started her first day to look into stack exchange: code review, and then, she joined one of discussion - quicksort, she was amazed how she learned quickly in the place.

Her first reading starts from here:

http://codereview.stackexchange.com/questions/5648/any-way-to-make-this-recursive-function-better-faster/5661?newreg=7b2fea2453a54c15bc466355fea0891d

Learn from expert on code review:

http://codereview.stackexchange.com/questions/142808/quick-sort-algorithm/142853#142853

http://codereview.stackexchange.com/a/142853/123986

Julia also wrote a blog about quick sort in 2016:

http://juliachencoding.blogspot.ca/2016/02/quick-sort-practice-makes-difference.html

Julia's favorite reading:
 http://codereview.stackexchange.com/questions/77782/quick-sort-implementation?rq=1

Study stackoverflow profile:
http://codereview.stackexchange.com/users/507/loki-astari

Actionable Items:

Read more live discussion on stackoverflow code review sections, at least find 5 top talents in C++, and find 10 advises from them in a week.

1. First one: Loki astari

Study stackoverflow profile:
http://codereview.stackexchange.com/users/507/loki-astari

Julia's favorite learning on Nov. 25, 2016:

-- start learning: 

http://codereview.stackexchange.com/a/77821/123986

 - 

Compilers Job

Don't do work the compiler can do for you:
int arr[8] = {110, 5, 10,3 ,22, 100, 1, 23};
The compiler is better than you at it anyway and it will prevent errors. Here you have said the number of elements is 8. As a human I can't see that at a glance I could count them to verify but as a human I am lazy and going to assume you got it correct. If you did not get it correct then we will have problems.
So let the compiler work it out.
int arr[] = {110, 5, 10,3 ,22, 100, 1, 23};
Now if the array changes size you only have to change one thing (the data). Rather than two things (data and size).
 -- end of learning  --

Coding Style - Great advice on coding/ design, a hackerRank question:

http://codereview.stackexchange.com/questions/140825/keeping-track-of-the-tennis-score/140827#140827

Thursday, October 20, 2016

Tech events in 2016

Oct. 20, 2016

Introduction


Julia loves to attend tech events and meet people in the city of Vancouver and also in the city of Seattle in 2016. So far in 2016, she has attended more than 6 tech events. Two hosted by Microsoft, SQL server in Seattle (March 31, Microsoft Database Systems Engineering Open House), Vancouver Tech Woman in Vancouver (Sept.); Two hosted by Amazon (May 3, Amazon web service talk; June 23, RDS talk); One by Arista Network; One by Tableau, algorithm/ data structure interview workshop.

Seattle two day vacation - tech event trip

Such a beautiful season with tour of Seattle, so many good memories and good laughs with friends.

Microsoft:
In March of 2016, she took 2 days vacation and drove to the city of Seattle to attend Microsoft SQL server tech event, and visited her FAU classmates in Seattle.

And then, she visited the headquarter of Amazon, near union lake.

Tech events are fun
She had such great time to watch the video and learned a few things on Oct. 19, 2016

Grace Hopper Celebration of Women in Computing

https://www.facebook.com/gracehoppercelebration/



Entertainment episodes in tech event:

1. Episode 1

Personal coding blog is such an entertainment topic in tech event:

A senior principle programmer (A) and Julia's conversation:

A's Questions: Who can tell quicksort best performance or worst performance?

Julia:
I can tell, the worst of quicksort is linear. Because I just wrote a blog about quicksort.

A's question: where is the blog? Show me on my cellular phone?

Julia:

"Julia coding blog" search Google.com
"quick sort" search blog

2. Episode 2

A senior principle programmer (A) and Julia's conversation:

A's question: why do you write she instead of I?

Julia:
It is more close to reader, instead of I, I, I, too self-center; I choose to write as she likes; it is a style. More picky, close to reader instead using "I".

A's question: where is the code? Show me your code.

Julia:

...


2010 - 2015 five years


Julia attended more than 5 social events in the city of Vancouver (from 2010 to 2015) hosted by facebook. And almost every time, she asked around how to improve algorithm problem solving, being competitive on algorithm problem solving.

She learned a lot, but she wanted to be a competitive programmer.

After 5 years full time job as a software programmer, she knows how weak her thinking muscle on algorithm. So, she decided to change, journal her practice through her personal coding blog in the city of Vancouver.

2015 - Now


She decided to take some risk, and take algorithm problem solving as a highest priority in her life; she works on goals she has more control, like HackerRank contest performance improvement.

Writing is most challenging for her, so she started to write more through her coding blog, and also log her practice very honestly.

Best learning is by doing, not just reading other people's work; Best learning is also a sharing, willing to take some risk to make mistakes, share the pain, struggling to make a little progress every time, and get connected to more people, motivate others to work hard as well.

Share my favorite quote about practice - when to stop?