├── 1_1_QUESTIONS.md
├── BEHAVIORAL_CONCEPTS.md
├── BEHAVIORAL_QUESTIONS.md
├── CODING_CONCEPTS.md
├── CODING_EXERCISES.md
├── CODING_QUESTIONS.md
├── CONTRIBUTING.md
├── COVER_LETTER.md
├── DESIGN_EXERCISES.md
├── EXPRESSIONS.md
├── INTERVIEWING.md
├── JOB_CAREER.md
├── JOB_OFFERS.md
├── LICENSE.md
├── README.md
└── SALARY_NEGOTIATION.md
/1_1_QUESTIONS.md:
--------------------------------------------------------------------------------
1 | # 1:1 Questions
2 |
3 | - On a scale of 1-10, rate your overall satisfaction with your employment at this company.
4 | - What is the number one reason you get out of bed in the morning and come to work?
5 | - List three items you would like to have for your desk if budget was not a concern.
6 | - Is there any topic that comes up during the day that you feel confused or unclear about?
7 | - Is there anyone specifically that you have a hard time working with for any reason?
8 | - Do you feel challenged on a daily basis?
9 | - Do you feel competitive with your coworkers, or is it more of a teamwork environment?
10 | - Is there anyone within the company that you look up to, and why?
11 | - Is this job providing you with a good overall work/life balance?
12 | - Tell me your thoughts on my management style.
13 | - Do you feel like your education is being put to its maximum use in your position?
14 | - Are you proud of your work? What could we do to make you feel more pride in your job?
15 | - How can we change our staff meetings to make them more productive?
16 | - Tell me about your greatest accomplishment while employed here.
17 | - Would you like to work at home occasionally if that was offered to you?
18 | - How much longer will you be satisfied in your current position before receiving a promotion?
19 | - On a scale of 1-10 how much time do you feel is wasted in your day? What could we do to be more efficient?
20 | - Do you feel obligated to participate in any office activities that you would rather not be a part of?
21 | - As managers, what can we do to give your workday more direction?
22 | - If you were to receive a compensation increase, would you prefer higher pay or more benefits?
23 | - What three simple things could make your work days more enjoyable?
24 | - Describe a scenario that has arisen in your job that you don't feel you have the proper tools to handle effectively.
25 | - What would it take for you to leave this job for a new position?
26 | - Have you thought of any special projects that you would enjoy working on if given the opportunity?
27 | - Describe in detail the first hour of your normal work day.
28 | - Describe in detail the last hour of your normal work day.
29 | - Is there someone in the office that you would like to work more closely with?
30 | - Name something you do on a daily basis at work that you feel does not get enough attention or credit.
31 | - Do you want to be more involved in decision making, or do you prefer to enact the decisions of others?
32 | - Present me with a situation that you would like to know my response to.
33 | - List three things that you think the company as a whole should do to be more competitive.
34 | - What specific functions would you train a new employee on first?
35 | - In general, do you feel you are given enough opportunities to advance your career? If not, what more could be done to help move you towards your goals.
36 | - What is your personal opinion of the long term outlook for this company?
37 | - Do you see any market opportunities that the company is not taking advantage of?
38 | - What chances would you like to be given to feel more apart of the decision-making process?
39 | - What is one thing that could be done to make you feel more 'at home' in the office?
40 | - Who in the office do you think has knowledge that you could benefit from?
41 | - What are your big dreams in life? Is this job getting you closer to reaching them?
42 | - Have any outgoing employees expressed specific issues to you? What were they?
43 | - Do you feel the work is evenly distributed across the team? Is there anyone carrying too much? What are some ways we could even things out?
44 | - Are you uncomfortable giving any of your peers constructive criticism? If so, why?
45 | - What is something we could do as a team to improve the company?
46 | - What is an example of a "little thing" that really impressed you recently? (For example, great customer service or a well-designed product.)
47 | - Do you think the salary possibilities within this company are enough to satisfy you long term?
48 | - Tell me about a recent situation you wish you would have handled differently.
49 | - List 2 things that you see being done inefficiently around the office. Is it worth making them more efficient? Why or why not?
50 | - If you sat in on an interview for a prospective employee, what one question would you ask them?
51 | - If you were to give yourself a rating (1-10) today, what would it be?
52 | - In your opinion, is the staffing level in the office sufficient to keep up with the workload?
53 | - What about the physical arrangement of the office do you like? What would you change?
54 | - Tell me about the last time you felt proud of yourself to solving a problem on the job.
55 | - Is the job you perform on a daily basis what you expected when you took it?
56 | - Pick a question to ask your manager about their background or career. [this one is for the you to come up with!]
57 | - What's the best compliment you've ever received at work? [this one's for your manager to ask! phew, back to normal.]
58 | - List 3 things you would like to see when you come to work every day.
59 | - Is this job fitting in well with your life as a whole?
60 | - Are you happy that you left your previous job for this one?
61 | - How long can you see yourself working here?
62 | - Are you having fun? Tell me about the most fun you've had working here.
63 | - What is most important to our business -- mission, core values, or vision?
64 | - What are you doing really well that is moving you towards your career goals?
65 | - What parts of the business would you like to be more involved in or learn more about?
66 | - Sometimes an organization gets so focused on the tactical and day-to-day that they forget to take time to focus on being creative and fostering innovative ideas. What can we do to be more creative and innovative?
67 | - How often do people ask you for help? What do they ask for and how long does it take you?
68 | - Do you enjoy office functions (parties, dinners) or would you rather be rewarded in some other way?
69 | - How well-received do you feel your opinions are when you offer them up?
70 | - What goals do you feel like you have accomplished professionally since you began work here?
71 | - In what ways could we improve communications around the office?
72 | - On a scale of 1-10 what level of loyalty do you feel to the company as a whole?
73 | - Name the first two things you would do if you were put in charge for a day.
74 | - What is one thing we could do to make the office more comfortable/enjoyable/fun (or just better) without spending much money?
75 | - How well do you feel like you relate to you coworkers? Do you view them as friends?
76 | - Do you feel like you receive feedback often enough?
77 | - Who do you really admire?
78 | - What makes for a great day at work?
79 | - If money were no object, what would you do every day?
80 | - How often do you think staff meetings are needed to keep everyone on the same page?
81 | - Are you making as much money now as you hoped when you accepted the job?
82 | - List the top three things that you feel waste time during your day.
83 | - Without naming anyone specifically, do you know of anyone in the office that is unhappy?
84 | - If the need should arise, do you feel comfortable filling any roles other than your own in the office?
85 | - Have you been asked to do anything as part of your job that pushed your out of your comfort zone?
86 | - From a resources standpoint, is there anything that would help you do your job better?
87 | - Speaking honestly, what is one criticism you would have for me?
88 | - When have you had the most fun at work? (And it doesn't have to be this company! It can be past roles too.)
89 | - Generally speaking, are you happy being employed here?
90 | - What are 1 or 2 things in our team that could be done more efficiently?
91 | - What is one thing that I, or the company, could to do support you in achieving your goals?
92 | - How could your working hours be adjusted to better fit your schedule?
93 | - When was the last time you got stuck and needed help at work? Who/what helped you get unstuck?
94 | - What part of your job do you enjoy the most? And which part do you enjoy least?
95 | - What is one thing we aren't currently doing, but could be doing to grow the business?
96 | - What part of your job do you wish you didn't have to do?
97 | - What are your top 3 super powers?
98 | - What is the biggest challenge we will face this year?
99 | - Tell me about your long term career goals.
100 | - What is a mistake you made recently that you learned a lot from?
101 | - Are there any areas of your job that you would like additional training in?
102 | - Tell me about one coworker that you feel does a particularly good job.
103 | - List three things that motivate you to do your work each day.
104 | - What is one thing that I could do to make you more productive?
105 | - What did you want to be when you grew up?
106 |
107 | ## Credits:
108 | - [@buritica](https://github.com/buritica)
109 |
--------------------------------------------------------------------------------
/BEHAVIORAL_CONCEPTS.md:
--------------------------------------------------------------------------------
1 | ## The STAR Method
2 | A structured manner of responding to a behavioural-based interview question by discussing the specific situation, task, action, and result of the situation you are describing.
3 |
4 | - Situation
5 | - Task
6 | - Action
7 | - Result
8 |
9 | ### Situation
10 | Describe the situation that you were in or the task that you needed to accomplish. You must describe a specific event or situation, not a generalized description of what you have done in the past. Be sure to give enough detail for the interviewer to understand. This situation can be from a previous job, from a volunteer experience, or any relevant event.
11 |
12 | ### Task
13 | What goal were you working toward?
14 |
15 | ### Action
16 | Describe the actions you took to address the situation with an appropriate amount of detail and keep the focus on YOU. What specific steps did you take and what was your particular contribution? Be careful that you don’t describe what the team or group did when talking about a project, but what you actually did. Use the word “I,” not “we” when describing actions.
17 |
18 | ### Result
19 | Describe the outcome of your actions and don’t be shy about taking credit for your behavior. What happened? How did the event end? What did you accomplish? What did you learn? Make sure your answer contains multiple positive results.
20 |
21 | > Be as specific as possible at all times, without rambling or including too much information.
22 |
23 | ## Axes
24 | - **Motivation**, self-motivated, passionate about real problems and company values.
25 | - **Empathy**, sees other's perspectives and motivations, fosters consensus and a collaborative work environment.
26 | - **Starting**, shows initiative, balances analysis, breaks work into chunks.
27 | - **Finishing**, perseveres, maintains focus, balances stress, lands projects.
28 | - **Able to work in an unstructured environment**, deals with ambiguity, promotes global ownership.
29 | - **Conflict Resolution**, handles challenging relationships appropriately.
30 | - **Growth**, knows their own strengths, recognizes their growth areas, invests in self-improvement.
31 | - **Communication**, uses clear, concise, compelling language.
32 |
33 | ## How to prepare for a Behavioral interview?
34 |
35 | Recall recent situations that show favorable behaviors or actions, especially involving course work, work experience, leadership, teamwork, initiative, planning, and customer service.
36 | - Prepare short descriptions of each situation; be ready to give details if asked.
37 | - Be sure each story has a beginning, middle, and an end, i.e., be ready to describe the situation, including the task at hand, your action, and the outcome or result.
38 | - Be sure the outcome or result reflects positively on you (even if the result itself was not favorable).
39 | - Be honest. Don't embellish or omit any part of the story. The interviewer will find out if your story is built on a weak foundation.
40 | - Be specific. Don't generalize about several events; give a detailed accounting of one event.
41 | - Vary your examples; don’t take them all from just one area of your life.
42 |
--------------------------------------------------------------------------------
/BEHAVIORAL_QUESTIONS.md:
--------------------------------------------------------------------------------
1 | # Behavioral Questions
2 |
3 | - How do you work with others?
4 | - How open are you to receiving feedback?
5 | - Tell me about a time where you made a mistake in a previous project/job.
6 | - Describe a situation where you had to complete a task/goal, and you could achieve it.
7 | - Give me an example of a time when you disagreed with a colleague.
8 | - Is there something you would like to ask?
9 | - What have you done in the last 3 jobs?
10 | - What is your experience working for startups?
11 | - What are your expectations in general for your new job?
12 | - Tell me about a time when you had to provide constructive feedback to a team member.
13 | - From the technical perspective:
14 | - How do you want to be managed?
15 | - Which challenges are you expecting to be facing here?
16 | - What are your 3 motivations to join this project?
17 |
18 |
19 | > Prepare sticky notes.
20 |
21 | ## Examples
22 |
23 |
24 | Describe a situation in which you were able to use persuasion to successfully convince someone to see things your way.
25 |
26 | - Creating a new template with ASP.NET MVC to work with designers in a better way (Separation of concerns for the win, instead of using server-side controls).
27 | - Use hybrid mobile frameworks (depending of the app) to reduce time to market and helping other teams (Become Ionic partners).
28 | - Creating new native plugins to give a better user experience (Open Source projects).
29 |
30 |
31 |
32 | Describe a time when you were faced with a stressful situation that demonstrated your coping skills.
33 |
34 | - Working until the next day for a release to production (BevyUp)
35 | - My cat walking on the balcony (During a demo with the client)
36 | - Situation: I was in a meeting with a client, presenting a demo, when suddenly my wife appeared very scared and asked me for help because something was happening, then I realized that my little cat was walking on the edge of the balcony, I had to pause my presentation because I was so worried.
37 | - Task: Ask for a break and rescue my cat.
38 | - Action: I had to be brave and rescue the cat, then I was able to finish the presentation.
39 | - Result: I was able to face that so stressful situation because I was thinking in the solution instead of the problem, and then I was calm because I had been able to finish the presentation with the help of my team.
40 | - A PoC with a new technology in a short period of time (StartUp Acquisition)
41 | - Working in a project with 1 week sprints (working weekends)
42 | - Excel generation tool migration with a class having more than 30k lines of code and without business formulas.
43 | - Situation: Code refactor of a software with more than 10 years in the market, and having classes of more than 30k lines of code, where the client did not know the formulas of the business with which more than 30 different critical excel files were exported.
44 | - Task: Looking to improve the UX (performance) for generating these files.
45 | - Action: I had to contribute to Open Source and created interfaces to simulate functionalities of a deprecated library. I spent some months working on this migration.
46 | - Result: Using benchmarks I was able to compare these tools, and I found some issues during this migration but with the help of these Open Source contributions (reporting issues, discussing and reviewing the code of the external lib) I was able to solve unforeseen problems.
47 |
48 |
49 |
50 | Give me a specific example of a time when you used good judgment and logic in solving a problem.
51 |
52 | - Creating a new Open Source project to improve UX with a native look & feel (React Native InAppBrowser).
53 | - Use memoization and Big O notation to reduce complexity with RxJS subscriptions.
54 | - Found SQL Injection issues concatenating Database queries from a third party system.
55 | - Using hooks to reduce code complexity and increase test coverage.
56 | - Using macros from Assembly lenguage to reduce complexity.
57 |
58 |
59 |
60 | Give me an example of a time when you set a goal and were able to meet or achieve it.
61 |
62 | - Using a new strategy to implement a real-time connection.
63 | - Database migration from NoSQL (MongoDB) to SQL & Multi-tenant (PostgreSQL) takes less than 3 months.
64 |
65 |
66 |
67 | Tell me about a time when you had to use your presentation skills to influence someone's opinion.
68 |
69 | - Comparison between React Native and NativeScript for cross-platform native UI apps.
70 | - Web Components and compilers instead of a Framework (Be agnostic, it Depends... maybe You don't need it).
71 | - Using promises for HTTP requests from Unity.
72 | - Divide and conquer (Avoid blocking tasks)
73 | - Situation: Implementing new features from a React Native app was giving us some problems, specially because we're using React class components with nested code, having complex local states with large components and repeated code, so it was difficult to maintain unit tests and increase test coverage.
74 | - Task: My goal was to help another Senior developer with a new feature adding a real-time connection from some screens of a chat module and increasing the test coverage of a complex component.
75 | - Action: We had some sessions of pair programming but I was stuck waiting for my partner to finish the dependent task assigned to him, so I decided to investigate on my own how to reduce the complexity of the current code and avoid adding nested code to the chat component. I learned about a new way to reuse code, extend behaviors easily and have components as small functions using functional programming and React hooks, while also implementing the real-time connection. As my colleague did not agree to do it in a different way, I proceeded to speak with the PM about the advantages that this new utility offered us and I made a presentation to share the knowledge gained about this new React feature with the rest of the team.
76 | - Result: We agreed with the team to use this new strategy for this implementation and thanks to this we were able to finish the feature 2 weeks ahead of schedule and increase test coverage by 20% by having small features that were much easier to maintain and test. Also, a few months later I made a talk about these topics for the rest of the company and it was shared on YouTube.
77 |
78 |
79 |
80 | Give me a specific example of a time when you had to conform to a policy with which you did not agree.
81 |
82 | - Using fingerprint to register arrival and departure time at work
83 |
84 |
85 |
86 | Please discuss an important written document you were required to complete.
87 |
88 | - Documenting multi-tenant architecture
89 | - Situation: Architecture documentation was required by the client.
90 | - Task: Create architecture documentation of the project about purpose, scope, business and technical architecture, data migration and deployment strategies, version management and environment set-up.
91 | - Action: I designed the first version of the document about architectural overview of the solution, to capture and convey the significant architectural decisions which have been made on the system.
92 | - Result: The documentation created was a good guide for new developers to understand the scope of the project, listing all definitions, references and human operations involved to support business processes which are triggered and generate business events. With this guide I defined each business process, design patterns and principles used in the project, coding conventions, describing frameworks, services and dependencies involved in the execution, defining the tiers where the software components are deployed and executed, listing functional and non-functional requirements and about technical architecture I generated component, deployment, package, use case and entity relationship diagrams to illustrate the logical structure and organization of the project. I identified opportunities for improvement about deployment strategies to automate the process publishing new releases to Production environment and avoiding risks to access to the database externally due to default configurations.
93 |
94 |
95 |
96 | Tell me about a time when you had to go above and beyond the call of duty in order to get a job done.
97 |
98 | - Use personal time to update deprecated templates and avoid code refactors of the project in the future.
99 | - Create a fully working prototype instead of a PoC to make a good impression with a partner.
100 | - Committed working in a PoC until early the next day.
101 | - Attending a meeting with the client while I was in a recreational activity of the company (playing bowling with coworkers).
102 | - Working in a presentation during weekends for all-hands meeting.
103 |
104 |
105 |
106 | Tell me about a time when you had too many things to do and you were required to prioritize your tasks.
107 |
108 | - Daily meetings to prioritize tasks.
109 | - Stoping/Delegating my tasks to help coworkers and other teams of the project (Releases to production, Hotfixes).
110 |
111 |
112 |
113 | Give me an example of a time when you had to make a split second decision.
114 |
115 | - Reverting deployment testing on production (CodePush not working with a hotfix to log native exceptions).
116 | - Stop a presentation with the client to rescue my cat while he was walking on the balcony outdoor.
117 |
118 |
119 |
120 | What is your typical way of dealing with conflict? Give me an example.
121 |
122 | - Take the decision with the rest of the team.
123 | - Analyze other perspectives, but review what we did and let's see what to do for improvement (Flexible).
124 | - Keep a cool head because it's just work (New PMs, coworkers getting frustration, etc).
125 |
126 |
127 |
128 |
129 | Tell me about a time you were able to successfully deal with another person even when that individual may not have personally liked you (or vice versa).
130 |
131 |
132 | - It's work, never mix business with personal matters (Loss of professionalism, maintain a balance between personal and professional lives).
133 | - PM taking bad decisions with the client, so taking decisions with the rest of the team and the software architect.
134 |
135 |
136 |
137 | Tell me about a difficult decision you've made in the last year.
138 |
139 | - Study for this interview, remember concepts that I'd not reviewed since college (Practice algorithms and many other things in a short time)
140 | - Situation: Many other professionals prepare months and even years to present themselves to a FAANG company, this is my first time and the recruiter contacted me because of my contributions, I was not prepared, It has really been a lot of work these days, preparing for these meetings, a lot to do in a short time.
141 | - Taking a remote job with only 4 months working as a Software Architect in another company
142 |
143 |
144 |
145 | Give me an example of a time when something you tried to accomplish and failed.
146 |
147 | - A big refactor took longer than estimated
148 |
149 |
150 |
151 | Give me an example of when you showed initiative and took the lead.
152 |
153 | - Help the company to be a trusted partner of a technology by sharing my own side projects
154 |
155 |
156 |
157 | Tell me about a recent situation in which you had to deal with a very upset customer or coworker.
158 |
159 | - Perfect is the enemy of good having strict deadlines (Done is better than perfect)
160 |
161 |
162 |
163 | Give me an example of a time when you motivated others.
164 |
165 | - Being speaker in local communities like CodeYourFuture
166 | - Helping another developer to get a new role (Being a mentor)
167 |
168 |
169 |
170 | Tell me about a time when you delegated a project effectively.
171 |
172 | - Delegating leadership while helping to develop her confidence **(nobody is indispensable, avoid comfort zones, upgrade her skills, adopt a proactive approach)**
173 |
174 |
175 |
176 | Give me an example of a time when you used your fact-finding skills to solve a problem.
177 |
178 | - Stranger things with the code (Strange behaviors, code not working as expected)
179 | - Creating templates and fixing issues learning new technologies with Open Source projects
180 |
181 |
182 |
183 | Tell me about a time when you missed an obvious solution to a problem.
184 |
185 | - Ignoring brute force solutions thinking about Big O Notation and Cyclomatic complexity
186 |
187 |
188 |
189 | Describe a time when you anticipated potential problems and developed preventive measures.
190 |
191 | - Sharing with the team about semantic versioning and the correct way to use that with CodePush from production
192 |
193 |
194 |
195 | Tell me about a time when you were forced to make an unpopular decision.
196 |
197 | - Not using Redux (Popular State management). I'll never know. I got the outcome I wanted, but I might have gotten a better result by handling it differently.
198 |
199 |
200 |
201 | Please tell me about a time you had to fire a friend.
202 |
203 | - Informed but they didn't take me into account
204 |
205 |
206 |
207 | Describe a time when you set your sights too high (or too low).
208 |
209 | - Being a perfectionist and trying to do everything on my own (not settling for what already exists and works, but trying to improve it)
210 |
211 |
212 |
213 | Let's say one of your peers on your team is underperforming. What would you do (if anything)?
214 |
215 | - Divide complex tasks and help my partner by having peer programming sessions to share knowledge or 1-1 meetings to discuss what I can do to help him/her improve in his/her career, I could help him/her with a mentoring process to define some **KPOs (Key Performance Objectives)** to continue growing and looking for him/her to take on new challenges in the project by delegating.
216 |
217 |
218 |
219 | What work have you found most technically challenging in your career and why?
220 |
221 |
222 |
223 | What work have you done that you were particularly proud of and why?
224 |
225 |
226 |
227 | When have you been happiest in your professional career and why?
228 |
229 |
230 |
231 | When have you been unhappiest in your professional career and why?
232 |
233 |
234 |
235 | ## Remember
236 | - Be yourself; mention where I have been wrong, I have failed **(Everyone makes mistakes)** and express the initiatives that I have taken.
237 | - Talk more about what I did, instead of talking so much about what we did as a team; e.g: I disccused with the manager, I shared a technical presentation with the team and together we managed to decide this. Talk with your team
238 | - There have been several situations where I failed, did I communicate it in time? it is important to mention it
239 | - Be honest, express if I made bad decisions, if it took me longer, and that I learned from the process.
240 | - How do you interact with the team?
241 | - How do I react to failure? Show what I learned from the experience to avoid repeating the same mistakes.
242 | - Give numbers, coverage improved, how much percentage? improved sales, how much? Did the decisions I made help make life easier for users?
243 | - Focused more about the product and business than technology, its important to ask yourself what are we doing? what is the goal of what we are building? to align the vision with the product team.
244 | - Show them you take responsibility for mistakes.
245 | - Keep it brief and concise. Try to tell the story in chronological order, too, without having to go back and forward in time repeatedly.
246 |
247 | ## Credits:
248 | - [Interview Questions and Answers by LinkedIn](https://www.linkedin.com/interview-prep)
249 | - [The STAR Method of Behavioral Interviewing](https://www.vawizard.org/wiz-pdf/STAR_Method_Interviews.pdf)
250 | - [@RamirezAlex](https://github.com/RamirezAlex)
251 |
--------------------------------------------------------------------------------
/CODING_CONCEPTS.md:
--------------------------------------------------------------------------------
1 | ## Dynamic Programming
2 | Dynamic Programming (DP) is a similar approach to Divide & Conquer. It also breaks the problem into similar subproblems, but they are actually overlapping and codependent — they’re not solved independently.
3 | Each subproblem’s result can be used anytime later and it is built using memoization (precalculation). DP is mostly used for (time & space) optimization and it is based on finding a recurrence.
4 |
5 | ## Big O Notation
6 | A method which describes algorithm complexity, the execution time required or the space used in memory by an algorithm, where "n" represents size of the data structure.
7 |
8 | ### Time complexity
9 | Describe the rough estimate of the number of "steps" to complete the algorithm.
10 |
11 | - **Rules:**
12 | * O(1) * O(n) = O(n) ------------ do something n times => loop
13 | * O(n) * O(n) = O(n^2) ------------ outer loop runs n times * inner loop runs n times (nested loop)
14 | * O(1) + O(n) = O(n) ------------ constant time + loop
15 | * O(n) + O(n^2) = O(n^2) ---------- loop + loop with nested loop
16 | * O(1) + O(n) + O(n^2) = O(n^2)
17 | * O(1) + O(n/2) + O(100) = O(n) --- As n gets really big, any operation has a decreasingly significant effect
18 | * O(n^3 + 50n^2 + 10000) = O(n^3)
19 | * O((n+30) * (n+5)) = O(n^2)
20 |
21 | > Assuming "n" becomes very large, the notation with slower increase speed could be ignored 🐌 (as the nature of large scale data in computer engineering, everything else is quickly eclipsed as n gets very large)
22 |
23 | - **Speed:** `O(1) < O(log(n)) < O(n) < O(n log(n)) < O(n^2)`
24 |
25 | - **Sort Algorithms (Worst case):**
26 | * Mergesort, Timsort, Heapsort = `O(n log(n))`
27 | * Quicksort, Bubble Sort, Insertion Sort, Selection Sort = `O(n^2)`
28 |
29 | ### Space complexity
30 | About memory cost, to optimize an algorithm for using less memory.
31 | When comparing different algorithms, we often compare how much "extra" space complexity is needed to solve the problem.
32 | In an algorithm, we need to create an array of size n to store the temporary results before getting the final result. If we assume that the size of a element in the array is a constant "C" which is independent to "n", the space complexity for using the array is Cn which is `O(n) * O(C) = O(n) * O(1) = O(n)`
33 |
34 | > O(1) space complexity if more efficient than O(n)
35 |
36 | - **Data Structures:**
37 | * Array, Stack, Queue, Hash Table, BST = `O(n)`
38 | * Skip list = `O(n log(n))`
39 | - **Sort Algorithms:**
40 | * Heapsort, Bubble Sort, Insertion Sort, Selection Sort = `O(1)`
41 | * Quicksort = `O(log(n))`
42 | * Mergesort, Timsort = `O(n)`
43 |
44 | ## LIFO
45 | Last In, First Out, e.g: Stacks
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | ## FIFO
54 | First In, First Out, e.g: Queues
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | ## Call stack
63 | A stack data structure that stores information about the active subroutines of a computer program. (also known as an execution stack, program stack, control stack, run-time stack, or machine stack). It's used to keep track of the point to which each active subroutine should return control when it finishes executing. An active subroutine is one that has been called, but is yet to complete execution, after which control should be handed back to the point of call.
64 | ## Graphs
65 | Graphs are used to represent networks. It's a data structure that consists of the following two components:
66 | - A finite set of vertices also called as nodes.
67 | - A finite set of ordered pair of the form (u, v) called as edge. The pair of the form (u, v) indicates that there is an edge from vertex u to vertex v. The edges may contain weight/value/cost.
68 | Example:
69 | ```sh
70 | (u, v)
71 | [0] -- [1]
72 | | / \
73 | | / [2]
74 | | / /
75 | [4] -- [3]
76 | ```
77 | ### Adjacency Matrix
78 | A 2D array of size V x V where V is the number of vertices in a graph (used to represent weighted graphs). e.g:
79 | ```ts
80 | [[0, 1, 0, 0, 1],
81 | [1, 0, 1, 0, 1],
82 | [0, 1, 0, 1, 0],
83 | [0, 0, 1, 0, 1],
84 | [1, 1, 0, 1, 0]];
85 | ```
86 | * Consumes more space O(V^2).
87 | * Adding a new vertex the storage must be increases to (|V|+1)^2, complexity is O(V^2).
88 | * Adding an edge requires O(1) time.
89 | * Removing a vertex the storage must be decreased to V^2 from (|V|+1)^2, complexity is O(V^2).
90 | * Removing an edge takes O(1) time.
91 | * Finding for an existing edge, given two vertices, can be checked in O(1) time.
92 | ### Adjacency List
93 | A graph is represented as an array of linked list. The size of the array is equal to the number of vertices.
94 | ```ts
95 | [
96 | [1, 4],
97 | [0, 2, 4],
98 | [1, 3],
99 | [2, 4],
100 | [0, 1, 3]
101 | ];
102 | ```
103 | * Saves space O(|V|+|E|).
104 | * Adding a vertex is easier O(1).
105 | * Adding an edge requires O(1) time.
106 | * Removing a vertex takes O(|V|+|E|) time (search for the vertex and traverse the edges).
107 | * Removing an edge takes O(|E|) time (traversing through the edges).
108 | * Queries like whether there is an edge from vertex u to vertex v are not efficient and can be done O(V).
109 |
110 | ## Tree traversal (walking the tree)
111 | Refers to the process of visiting (checking and/or updating) each node in a tree data structure, exactly once. As a tree is a self-referential (recursively defined) data structure, traversal can be defined by recursion or, more subtly, corecursion, in a very natural and clear fashion; in these cases the deferred nodes are stored implicitly in the call stack.
112 | ### Traversing a tree
113 | Involves iterating over all nodes in some manner:
114 |
115 | 
116 |
117 | #### Depth-first search (DFS)
118 | Starts at the root node and explores as far as possible along each branch before backtracking, with a DFS you push the children of the current node onto a stack, so they will be popped and processed before everything else. It's easily implemented via a stack, including recursively via the call stack:
119 | * Pre-order (NLR): It's a topologically sorted one, because a parent node is processed before any of its child nodes is done.
120 | * In-order (LNR): Retrieves the keys in ascending sorted order.
121 | * Reverse in-order (RNL): Retrieves the keys in descending sorted order.
122 | * Post-order (LRN): The trace of a traversal is called a sequentialisation of the tree. The traversal trace is a list of each visited root.
123 | #### Breadth-first search (BFS)
124 | Starts at the tree root and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level, with a BFS you push the children onto the end of a queue, so they will be popped and processed after everything else. It's easily implemented via a queue, including corecursively.
125 |
126 | ## Credits:
127 | - [Tech Interview Handbook](https://yangshun.github.io/tech-interview-handbook)
128 | - [Coding Interview University](https://github.com/jwasham/coding-interview-university)
129 | - [Complete Introduction to the 30 Most Essential Data Structures & Algorithms](https://dev.to/iuliagroza/complete-introduction-to-the-30-most-essential-data-structures-algorithms-43kd)
130 | - [Introduction to Big O Notation and Time Complexity](https://youtu.be/D6xkbGLQesk)
131 | - [To study runtime complexity: Big O Cheat Sheet](https://www.interviewcake.com/article/python/big-o-notation-time-and-space-complexity)
132 | - [The ultimate guide for data structures & algorithm interviews](https://dev.to/rahhularora/the-ultimate-guide-for-data-structures-algorithm-interviews-npo)
133 | - [OOP Principles For Dummies](https://dev.to/tamerlang/oop-principles-for-dummies-2mbd)
134 | - [Graph Algorithms](https://github.com/kdn251/interviews#graph-algorithms)
135 | - [Queues and Stacks](https://thagomizer.com/blog/2016/05/06/algorithms-queues-and-stacks.html)
136 |
--------------------------------------------------------------------------------
/CODING_EXERCISES.md:
--------------------------------------------------------------------------------
1 | ## Algorithms
2 | - Dijkstra (Shortest paths between nodes in a graph)
3 | - Rabin-Karp (a string-searching that uses hashing to find an exact match of a pattern string in a text)
4 | - Aho–Corasick (a string-searching that locates elements of a finite set of strings within an input text like "dictionary-matching")
5 |
6 | ## Arrays
7 |
8 | ### Given an array of size N in which every number is between 1 and N, determine if there are any duplicates
9 | ```ts
10 | // Time complexity: O(n^2) - BAD
11 | function hasDup (list: Array): boolean {
12 | for (let i = 0; i < list.length; i++) {
13 | for (let j = i+1; j < list.length; j++) {
14 | if (list[i] === list[j]) return true
15 | }
16 | }
17 | return false
18 | }
19 | // Time complexity: O(n) - GOOD
20 | function hasDup (list: Array): boolean {
21 | list.sort()
22 | for (let i = 0; i < list.length - 1; i++) {
23 | if (list[i] === list[i+1]) return true
24 | }
25 | return false
26 | }
27 | ```
28 |
29 | ### Given an array of words, get a list of these words bucket by anagrams
30 | ```sh
31 | Input: ["star", "rats", "car", "arc", "xml"]
32 | Output: [["star", "rats"], ["car", "arc"], ["xml"]]
33 | ```
34 | ```ts
35 | function getWordsBucketByAnagram(list: Array): Array> {
36 | const bucket: { [key: string]: Array } = {}
37 | for (let i = 0; i < list.length; i++) {
38 | const word = list[i]
39 | const key = word.split('').sort().join('')
40 | bucket[key] = [...(bucket[key] || []), word]
41 | }
42 | return Object.keys(bucket).map(key => bucket[key]) // Same as Object.values(bucket)
43 | }
44 | console.log(getWordsBucketByAnagram(["star", "rats", "car", "arc", "xml"]))
45 | ```
46 |
47 | ### Given a list of calendar events, determine if any events conflicts
48 | ```sh
49 | [
50 | [1, 2, 'a'], // start, end, id
51 | [3, 5, 'b'], -┐
52 | [4, 6, 'c'], -┘
53 | [7, 10, 'd'], -┐
54 | [8, 11, 'e'], |
55 | [10, 12, 'f'], -┘
56 | [13, 14, 'g']
57 | ];
58 | ```
59 | ```ts
60 | // SOLUTION 1: Brute force; Compare every event to every other event, Slow => O(n^2) complexity
61 | // SOLUTION 2: If the list is sorted, you can just compare the previous event, O(n) complexity
62 | function getConflicts (events: Array>) {
63 | return events.reduce(function (result, event, index) {
64 | const previousEvent = events[index-1]
65 | if (previousEvent && event[0] < previousEvent[1]) {
66 | result.push(event[2])
67 | }
68 | return result
69 | }, [])
70 | }
71 | // SOLUTION 3: Merge conflicts of the sorted list of events
72 | function findConflicts (events) {
73 | let conflicts = []
74 | let temp = [events[0][2]]
75 | let end = events[0][1]
76 | for (let i = 1; i < events.length; i++) {
77 | if (events[i][0] >= end) { // No conflict :)
78 | if (temp.length > 1) {
79 | conflicts = conflicts.concat(temp)
80 | }
81 | temp = []
82 | }
83 | end = Math.max(events[i][1], end)
84 | temp.push(events[i][2])
85 | }
86 | if (temp.length > 1) {
87 | conflicts = conflicts.concat(temp)
88 | }
89 | return conflicts
90 | }
91 | ```
92 |
93 | ### Given a table for N people, figure out every possible seating of the table for all of your friends
94 | ```sh
95 | # SOLUTION: Power set
96 | start
97 | leave | take
98 | |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
99 | - 1
100 | |‾‾‾‾‾‾‾‾‾‾‾‾‾| |‾‾‾‾‾‾‾‾‾‾‾‾‾|
101 | -- -2 1- 12
102 | | | | |
103 | |‾‾‾‾‾| |‾‾‾‾‾| |‾‾‾‾‾| |‾‾‾‾‾|
104 | --- --3 -2- -23 1-- 1-3 12- 123
105 | | | |
106 | -234 1-34 12-4
107 | ```
108 | ```ts
109 | /**
110 | * Power set
111 | * Time complexity: O(2^n)
112 | */
113 | function findDinnerParties(friends: Array, tableSize: number) {
114 | function combineFriends(
115 | friends: Array,
116 | tableSize: number,
117 | groups: Array> = [],
118 | group: Array = [],
119 | pos = 0
120 | ) {
121 | if (group.length === tableSize) groups.push(group)
122 | else if (pos < friends.length) {
123 | combineFriends(friends, tableSize, groups, group, pos + 1)
124 |
125 | const newGroup = [...group]
126 | newGroup.push(friends[pos])
127 |
128 | combineFriends(friends, tableSize, groups, newGroup, pos + 1)
129 | }
130 | return groups
131 | }
132 |
133 | return combineFriends(friends, tableSize)
134 | }
135 | findDinnerParties(['Sara', 'Juan', 'Valentina', 'Julian', 'Laura'], 3)
136 | ```
137 |
138 | ## Sorting
139 |
140 | ### Merge Sort
141 | ```ts
142 | function mergeSort(arr: Array): Array {
143 | if(arr.length <= 1) return arr;
144 |
145 | const mid = Math.ceil(arr.length / 2);
146 | const left = mergeSort(arr.splice(0, mid));
147 | const right = mergeSort(arr.splice(-mid));
148 |
149 | const result = [];
150 | while(left.length && right.length){
151 | if(left[0] > right[0]) {
152 | result.push(right.shift());
153 | } else {
154 | result.push(left.shift());
155 | }
156 | }
157 | return [
158 | ...result,
159 | ...left,
160 | ...right
161 | ];
162 | }
163 | ```
164 |
165 | ### Quick Sort
166 | ```ts
167 | function quickSort(arr: Array): Array {
168 | if (arr.length < 2) {
169 | return arr;
170 | }
171 | const pivot = arr[Math.floor(Math.random() * arr.length)];
172 |
173 | const left = [];
174 | const right = [];
175 | const equal = [];
176 |
177 | for (let val of arr) {
178 | if (val < pivot) {
179 | left.push(val);
180 | } else if (val > pivot) {
181 | right.push(val);
182 | } else {
183 | equal.push(val);
184 | }
185 | }
186 | return [
187 | ...quickSort(left),
188 | ...equal,
189 | ...quickSort(right)
190 | ];
191 | }
192 | ```
193 |
194 | ## Binary trees
195 | ```ts
196 | class TreeNode {
197 | public left!: TreeNode
198 | public right!: TreeNode
199 | constructor (
200 | public value: number
201 | ) { }
202 | }
203 | ```
204 |
205 | ### Perform in order traversal on a binary tree
206 |
207 | ```ts
208 | function inOrder (node: TreeNode): Array {
209 | if (!node) return []
210 | return [
211 | ...inOrder(node.left),
212 | node.value,
213 | ...inOrder(node.right)
214 | ]
215 | }
216 | function addNode (node: TreeNode, value: number) {
217 | if(!node) return new TreeNode(value)
218 | if(value >= node.value) {
219 | node.right = addNode(node.right, value)
220 | } else {
221 | node.left = addNode(node.left, value)
222 | }
223 | return node
224 | }
225 | function setNodes (node: TreeNode, values: Array) {
226 | values.forEach(value => addNode(node, value))
227 | return node
228 | }
229 | const tree = new TreeNode(5)
230 | setNodes(tree, [8, 4, 3, 1])
231 | console.log(inOrder(tree)) // Output: [1, 3, 4, 5, 8]
232 | ```
233 |
234 | ### Given a binary tree, get the average value at each level of the tree
235 | ```sh
236 | Input:
237 | 4
238 | / \
239 | 7 9
240 | / \ \
241 | 10 2 6
242 | \
243 | 6
244 | /
245 | 2
246 | Output: [4, 8, 6, 6, 2]
247 | ```
248 | ```ts
249 | type Level = {
250 | total: number
251 | count: number
252 | }
253 |
254 | function collect (node: TreeNode, levels: Array, levelIndex = 0) {
255 | if(!node) return
256 | const level = levels[levelIndex]
257 | if (!level) {
258 | levels[levelIndex] = { total: node.value, count: 1 }
259 | } else {
260 | level.total += node.value
261 | level.count += 1
262 | }
263 | levelIndex++
264 | collect(node.left, levels, levelIndex)
265 | collect(node.right, levels, levelIndex)
266 | }
267 | function getAvgByLevel(node: TreeNode) {
268 | const levels: Array = []
269 | collect(node, levels)
270 | return levels.map(({ total, count }) => total / count)
271 | }
272 | const tree = new TreeNode(4);
273 | tree.left = new TreeNode(7);
274 | tree.left.left = new TreeNode(10);
275 | tree.left.right = new TreeNode(2);
276 | tree.left.right.right = new TreeNode(6);
277 | tree.left.right.right.left = new TreeNode(2);
278 | tree.right = new TreeNode(9);
279 | tree.right.right = new TreeNode(6);
280 | console.log(getAvgByLevel(tree))
281 | ```
282 |
283 | ## Graphs
284 | ```ts
285 | // Using Adjacency Matrix
286 | const graph =
287 | [[1, 1, 0, 0, 1, 0],
288 | [1, 0, 1, 0, 1, 0],
289 | [0, 1, 0, 1, 0, 0],
290 | [0, 0, 1, 0, 1, 1],
291 | [1, 1, 0, 1, 0, 0],
292 | [0, 0, 0, 1, 0, 0]];
293 | ```
294 |
295 | ### Returns whether there's a path between two nodes in a graph
296 | ```ts
297 | /**
298 | * DFS is easy to implement recursively because you can use the call stack as the stack.
299 | * Time complexity: O(|V|^2).
300 | */
301 | function hasPath(
302 | graph: Array>,
303 | current: number,
304 | goal: number
305 | ): boolean {
306 | const stack: Array = [];
307 | const visited: Array = [];
308 | stack.push(current);
309 | visited[current] = true;
310 | while (stack.length > 0) {
311 | const node = stack.pop();
312 | if (node === goal) {
313 | return true;
314 | }
315 | for (let i = 0; i < graph[node].length; i += 1) {
316 | if (graph[node][i] && !visited[i]) {
317 | stack.push(i);
318 | visited[i] = true;
319 | }
320 | }
321 | }
322 | return false;
323 | }
324 | console.log(hasPath(graph, 1, 5)) // Output: true
325 | ```
326 |
327 | ### Returns the shortest path between startNode and targetNode
328 | ```ts
329 | /**
330 | * BFS visits the neighbor vertices before visiting the child vertices, and a queue is used in the search process.
331 | * Time complexity: O(|V|^2).
332 | */
333 | function shortestPath (
334 | graph: Array>,
335 | startNode: number,
336 | targetNode: number
337 | ): Array | null {
338 | const parents = [];
339 | const queue = [];
340 | const visited = [];
341 | queue.push(startNode);
342 | parents[startNode] = null;
343 | visited[startNode] = true;
344 | while (queue.length > 0) {
345 | const current = queue.shift();
346 | if (current === targetNode) {
347 | return buildPath(parents, targetNode);
348 | }
349 | for (var i = 0; i < graph.length; i += 1) {
350 | if (i !== current && graph[current][i] && !visited[i]) {
351 | parents[i] = current;
352 | visited[i] = true;
353 | queue.push(i);
354 | }
355 | }
356 | }
357 | return null;
358 | }
359 | function buildPath (
360 | parents: Array,
361 | targetNode: number
362 | ): Array {
363 | const result = [targetNode];
364 | while (parents[targetNode]) {
365 | targetNode = parents[targetNode];
366 | result.push(targetNode);
367 | }
368 | return result.reverse();
369 | }
370 | console.log(shortestPath(graph, 1, 5)) // Output: [1, 2, 3, 5]
371 | ```
372 |
373 | ### Given a graph represented as an adjacency lists and a source vertex, get an array of objects describing each vertex with the distance from the source and the vertex's predecessor
374 | ```ts
375 | type Vertex = {
376 | distance: number,
377 | predecessor: number | null
378 | }
379 | function getVertexDistanceAndPredecessor (
380 | graph: Array>,
381 | source: number
382 | ): Array {
383 | const bfsInfo: Array = [];
384 | bfsInfo[source] = {
385 | distance: 0,
386 | predecessor: null
387 | };
388 | const queue: Array = [];
389 | queue.push(source);
390 |
391 | while (queue.length > 0) {
392 | const current = queue.shift() as number;
393 | for (let i = 0; i < graph[current].length; i++) {
394 | const v = graph[current][i];
395 | if (!bfsInfo[v]) {
396 | bfsInfo[v] = {
397 | predecessor: current,
398 | distance: bfsInfo[current].distance + 1
399 | };
400 | queue.push(v);
401 | }
402 | }
403 | }
404 | return bfsInfo;
405 | }
406 | ```
407 |
408 | ## Search
409 |
410 | ### Binary Search
411 | ```ts
412 | function binarySearch(arr: Array, goal: number): number {
413 | let low = arr[0]
414 | let high = arr[arr.length - 1]
415 | while (low < high) {
416 | const mid = Math.floor(low + (high-low)/2)
417 | if (arr[mid] > goal) {
418 | high = mid
419 | } else {
420 | low = mid + 1
421 | }
422 | }
423 | return high
424 | }
425 | ```
426 |
427 | ## Optimization
428 |
429 | ### Given a sorted array, insert a new element keeping the order
430 | ```ts
431 | function insertSorted(arr: Array, num: number) {
432 | let low = 0
433 | let high = arr.length
434 | while (low < high) {
435 | const mid = Math.floor(low + (high-low)/2)
436 | if (arr[mid] - num > 0) {
437 | high = mid
438 | } else {
439 | low = mid + 1
440 | }
441 | }
442 | return [
443 | ...arr.slice(0, low),
444 | num,
445 | ...arr.slice(low)
446 | ]
447 | }
448 | ```
449 |
450 | ## Real Life problems
451 |
452 | ### Duplicated Transactions
453 | Sometimes when a customer is charged, there is a duplicate transaction created. We need to find those transactions so that they can be dealt with. Everything about the transaction should be identical, except the transaction id and the time at which it occurred, as there can be up to a minute delay.
454 |
455 | A transaction is looks like:
456 | ```json
457 | {
458 | "id": 123,
459 | "sourceAccount": "my_account",
460 | "targetAccount": "coffee_shop",
461 | "amount": -30,
462 | "category": "eating_out",
463 | "time": "2018-03-12T12:34:00Z"
464 | }
465 | ```
466 |
467 | ```js
468 | // Input: list of transactions (Transaction[])
469 | findDuplicateTransactions(transactions)
470 | // Output: list of all the duplicate transaction groups, ordered by time ascending (Transaction[][])
471 | ```
472 |
473 | Find all transactions that have the same sourceAccount, targetAccount, category, amount, and the time difference between each consecutive transaction is less than 1 minute.
474 | ```js
475 | Array.prototype.flatMap = function(lambda) {
476 | return [].concat.apply([], this.map(lambda))
477 | }
478 | function diffMinutes(dt2, dt1)
479 | {
480 | const diff = (dt2.getTime() - dt1.getTime()) / 1000 / 60
481 | return Math.abs(diff)
482 | }
483 | // Sort with FP (Inmutability, Pure function)
484 | function sortFP (
485 | transactions,
486 | timeProp = 'time'
487 | ) {
488 | return [...transactions].sort(
489 | (a, b) => new Date(a[timeProp]) - new Date(b[timeProp])
490 | )
491 | }
492 |
493 | // return your result from this function
494 | function findDuplicateTransactions (transactions = []) {
495 | transactions = sortFP(transactions)
496 | /**
497 | * key: sourceAccount__targetAccount__category__amount
498 | * groups: Array