Logic Building Questions With Solutions
Logic Building Questions With Solutions
Arrays
Solution: Sort the array and return the second last element.
Solution: Use a loop to swap elements from start and end until the middle.
Solution: Sort both arrays and compare each element for equality.
Solution: Merge the arrays while maintaining sorted order using two pointers.
Solution: Use Kadane's Algorithm to find the subarray with the maximum sum.
Strings
Solution: Split the string by spaces, reverse each word, and join back.
Solution: Use a dictionary to count character frequencies, then find the first unique character.
Solution: Use a set to keep track of seen characters and build a new string.
Solution: Iterate through the string, count consecutive characters, and build the compressed string.
Functions
Solution: Write a recursive function to multiply the base number for the exponent times.
5. Implement a function to find the GCD (Greatest Common Divisor) of two numbers.
Solution: Divide the number by 2 repeatedly and store remainders to convert to binary.
1. Create a class `BankAccount` with methods to deposit, withdraw, and check balance.
Solution: Define a `BankAccount` class with methods `Deposit`, `Withdraw`, and `GetBalance`.
Solution: Define a `Rectangle` class with attributes for length and breadth, and methods for area
and perimeter.
3. Design a `Person` class with properties for name, age, and a method to display the details.
Solution: Create a `Person` class with attributes for name and age, and a method to display details.
4. Create a `Shape` base class and derive classes for `Circle`, `Square`, and `Rectangle`.
Solution: Create a base class `Shape` and derive specific shapes like `Circle` with additional
Solution: Define methods with the same name but different signatures (overloading) and override
6. Design an abstract class `Vehicle` with a method `StartEngine` and derive classes for `Car` and
`Bike`.
Solution: Create an abstract class `Vehicle` with an abstract method `StartEngine`, and derive
7. Implement a `Student` class with properties, constructors, and methods for managing student
data.
Solution: Define a `Student` class with constructors for initialization and methods to manage student
data.
C#
Solution: Use a `foreach` loop to iterate through the elements of a collection like an array or list.
Solution: Use LINQ queries like `.Max()` and `.Min()` to find values.
5. Create an interface `IShape` with methods for area and perimeter, and implement it in `Circle`
and `Rectangle`.
Solution: Create an interface `IShape` and implement methods `GetArea` and `GetPerimeter` in
derived classes.
Solution: Define an asynchronous method using `async` and await a task for operations.
Solution: Use `List<Employee>` and `OrderBy` to sort employees based on their salary.
WinForms
Solution: Design a form with text boxes for username and password, and a button to validate them.
Solution: Use a `ListBox` or `DataGridView` to display items, and add buttons for Add, Edit, and
Delete.
Solution: Use a `DataGridView` control and bind it to a `DataTable` for product details.
4. Develop a form to calculate the sum of two numbers using text boxes and a button.
Solution: Add two text boxes for numbers, a button to calculate, and display the result in a label.
Solution: Use a `Timer` control to update a label with the current time at regular intervals.
6. Create a notepad application with options to save, open, and edit text files.
Solution: Use `RichTextBox` for editing text, and provide Save/Open buttons with file dialogs.
Solution: Use buttons for operations and text boxes to display input and results.