LinkedIn Interview Questions
Practice with real LinkedIn interview questions
01
A Software Engineer was asked
Asked in 2024
Q. What are the different types of keys in a database, and how do primary, foreign, and unique keys differ?
Ans. In a database, keys are used to uniquely identify records and establish relationships between tables. The three main types of keys are:
1. Primary Key: A unique identifier for a record in a table. No two rows can have the same primary key value, and it cannot be null.
- Example: In a
users table, user_id can be a primary key.
2. Foreign Key: A field (or collection of fields) in one table that uniquely identifies a row of another table. This establishes a relationship between the two tables.
- Example: In an orders table, user_id can be a foreign key referencing the user_id in the users table.
3. Unique Key: Ensures that all values in a column are different. Unlike primary keys, unique keys can accept null values.
- Example: In a users table, email can be a unique key.
Here’s a simple SQL example to illustrate these keys:
In this SQL code, user_id is a primary key in the users table, while it serves as a foreign key in the orders table, linking orders to users. The email field is a unique key, ensuring no two users can have the same email address.
Software EngineerCore Concept
02
A Software Engineer was asked
Asked in 2024
Q. Can you explain the basic operations of arrays and strings in programming, and give an example of how to reverse a string using an array?
Ans. Arrays and strings are fundamental data structures in programming. An array is a collection of items stored at contiguous memory locations, while a string is an array of characters terminated by a null character.
Key Operations:
- Accessing: You can access elements using an index.
- Inserting: Inserting new elements requires shifting elements if the array is full.
- Deleting: This also requires shifting elements to maintain order.
- Searching: You can search for elements using algorithms like linear or binary search.
Here’s a simple example of reversing a string using an array in Python:
This code defines a function that reverses an input string by utilizing an array-like approach, demonstrating basic array operations such as indexing and swapping.
Software EngineerCore Concept
