Logo

dev-resources.site

for different kinds of informations.

Today I gave a C++ backend interview. Here’s how it went.

Published at
5/16/2024
Categories
uncategorized
datastructures
interview
performance
Author
smrtdvlpr
Author
9 person written this
smrtdvlpr
open
Today I gave a C++ backend interview. Here’s how it went.

I was just told by the HR that this round will be C++ focused and will also focus on other technical concepts. So I prepared the following concepts:

  • C++ Language
  • Data Structures and Algorithms
  • Performance
  • Computer Network

I didn’t have much time to prepare, but I relied on what I had already learned and building on top of that foundation. Here’s how I went about my preparation:

  1. C++ Preparation:
    • Medium Article: I found this amazing article on Medium which covered my weak topics. Interestingly, these weak topics are often the most frequently asked in interviews.
    • Github Notes: Another great resource I went through was this notes published on githubfor C++. This covers all the essential concepts and also highlights good questions and tricky concepts.
    • InterviewBit Questions: To bolster my confidence, I reviewed the most commonly asked C++ questions on InterviewBit. These questions served as great refreshers.
  2. Resume Preparation:
    • Past projects : I made sure to revise and go through my past projects, since they can be asked at any time during the interview.
  3. Computer Network:
    • For the Computer Networks section, I utilized resources from InterviewBit and GeeksforGeeks (GFG), focusing particularly on the topics I was less familiar with.

The Interview

Question 1: TCP vs UDP

  • Question : Explain the difference between TCP and UDP.
  • Answer : TCP (Transmission Control Protocol) is connection-oriented, ensuring reliable and ordered delivery of data. UDP (User Datagram Protocol), on the other hand, is connectionless and does not guarantee delivery, making it faster but less reliable. Since TCP is lossless protocol it is slower than UDP. Example of TCP can be website data or Financial information received through FIX protocol, whereas UDP example can be a video call or media streaming.

Question 2: TCP vs UDP Usage

  • Question : Where would you prefer to use TCP, and where UDP?
  • Answer : TCP is preferred for applications requiring reliable communication, such as web browsing (HTTP/HTTPS) and email (SMTP). UDP is suitable for real-time applications like video streaming and online gaming, where speed is crucial and occasional data loss is acceptable.

Question 3: Finding Target Sum in Vector

  • Question : Find a target sum in a vector.
  • Approach : Initially, I used brute force, then optimised it with binary search.
  • Follow-up : The interviewer asked why instead of using the traditional method of calculating:

mid = (low + high)/2;

Enter fullscreen mode Exit fullscreen mode

I used:


mid = low + (high-low)/2;

Enter fullscreen mode Exit fullscreen mode

I explained that using the below approach will avoid the case of overflow.He also asked if x/2 is faster than x >> 1. I answered bitshifting will be faster than dividing by 2. Then he corrected me, C++ optimizes these operations, so it doesn’t matter which one is used. Therefore, C++ by default uses bitshifting to divide here by 2. So I need not substitute /2 with >>1.

Question 4: Pass by Reference vs Pass by Value

  • Question : Explain Pass by Reference vs Pass by Value.
  • Answer : Passing by reference avoids duplicating the data, improving performance. However, it risks unintended modifications to the original data.
  • Follow-up : To prevent unintended changes, the interviewer suggested using the const keyword when passing arguments by reference.

Question 5: Copying uint8_t Variables

  • Task : Create four uint8_t variables with assigned integers and copy them into a uint32_t variable.
  • Approach : I mentioned two options: using memcpy and using bitwise operations (left shifting and ORing).
  • Follow-up : The interviewer instructed me to explore memcpy on my own. While attempting this, I encountered an error: “invalid conversion of type”. We discussed why cout doesn’t print uint8_t as an integer and the peculiarities of char* handling in cout.
  • Final Task : Segregate the uint32_t back into four uint8_t variables.

Key Learnings

The interview was a rigorous yet enlightening experience. It highlighted the importance of understanding both high-level concepts and low-level details in C++. Revising from various resources paid off, especially focusing on commonly asked questions and tricky concepts.

uncategorized Article's
30 articles in total
Favicon
7 Creative Ways to Use CSS3 Variables in Your Web Design Projects
Favicon
Revolutionize Your Websites Success with Cutting-Edge SEO Techniques
Favicon
Syncfusion Now Supports .NET 9!
Favicon
IT Security Positions in Hamburg: In-Demand Roles and Skills
Favicon
How is Graph stored in Memory?
Favicon
Today I gave a C++ backend interview. Here’s how it went.
Favicon
Manually install Android SDK on Ubuntu
Favicon
What’s in a (Meeting Room) name?
Favicon
An Introduction to Cloud Computing Deployment Models
Favicon
Exploring User Privacy in the Age of Language Models
Favicon
Why Your Perfect Code Might Kill Your Startup: The Power of Prototyping!
Favicon
Choosing a Certified Salesforce Consultant: Why It Matters
Favicon
The Seven Phases of the Software Development Life Cycle
Favicon
Story of an SQL query ~10x speed-up with a simple tweak
Favicon
Elevate Your Business with Salesforce Consulting Company
Favicon
Remote Salesforce Admin Recruiters to Level Up Your Project
Favicon
Why Companies Should Hire Remote Salesforce Developers
Favicon
Salesforce Staff Augmentation: Benefits, Prices & Solutions
Favicon
Tired of Evernote? Try Obsidian!
Favicon
Enhancing Reliability: Global Exception Handling in ASP.NET Core Web APIs
Favicon
ECS Copilot with SQS Autoscaling
Favicon
Are Fax numbers still relevant in 2023?
Favicon
Are Fax numbers still relevant in 2024?
Favicon
The Props Getters Pattern in React
Favicon
React forwardref- Implement dialog without parent component re-rendering
Favicon
Como configurar um teclado PC português para uso num mac
Favicon
What is the woocommerce_checkout_fields filter and use cases – WooCommerce
Favicon
OTP Verification Form in HTML CSS & JavaScript
Favicon
Rebase vs. Merge: Pros and cons
Favicon
Enabling gRPC server reflection

Featured ones: