Flipkart Interview Questions
Practice with real Flipkart interview questions
01
A Frontend Developer was asked
Asked in 2024
Q. Describe the core concepts of React components and props. How do they work together? Provide a code example.
Ans. React components are the building blocks of any React application. They are reusable pieces of UI that can manage their own state and receive data through props. Props (short for properties) are used to pass data from parent components to child components, allowing for dynamic rendering of UI based on data.
Example of React Component with Props:
In this example,
Greeting is a child component that receives a name prop from the App parent component. The App component passes the userName variable as a prop to Greeting, which then renders the greeting message with the name provided.
Key Concepts:
- Components can be either functional or class-based.
- Props are immutable and should not be modified within the child component, ensuring a unidirectional data flow.
- Components can manage their own state using hooks (like useState) or class state management.
Understanding components and props is essential for building maintainable and scalable React applications.Frontend DeveloperCore Concept
02
A Software Engineer was asked
Asked in 2024
Q. Can you explain the concept of Dynamic Programming and provide an example of solving the Fibonacci sequence problem using Dynamic Programming in JavaScript?
Ans. Dynamic Programming (DP) is an optimization technique used to solve complex problems by breaking them down into simpler subproblems. It is particularly useful for problems that exhibit overlapping subproblems and optimal substructure properties. The Fibonacci sequence is a classic example where DP can be applied.
Fibonacci Sequence:
The Fibonacci sequence is defined as follows:
- F(0) = 0
- F(1) = 1
- F(n) = F(n-1) + F(n-2) for n > 1
Recursive Approach (Inefficient):
This recursive solution has exponential time complexity due to repeated calculations of the same values.
Dynamic Programming Approach (Efficient):
We can optimize this using memoization or tabulation.
#### Memoization Example:
In this approach, we store the results of computed Fibonacci numbers in a
memo object to avoid redundant calculations, achieving linear time complexity O(n).
#### Tabulation Example:
The tabulation method builds up the solution iteratively and also runs in O(n) time with O(n) space complexity.
Conclusion:
Dynamic Programming is a powerful technique to optimize recursive algorithms. By using memoization or tabulation, we can significantly reduce the time complexity of problems like calculating Fibonacci numbers from exponential to linear.Software EngineerCore Concept
