something
Wissen only
----------------
"1.reverse the string code
import java.util.*;
import java.lang.*;
class main{
public static String reverseString(String str)
{
String s[] = str.split(" ");
StringBuilder reverse = new StringBuilder();
int n = s.length;
for(int i=n-1;i>=0;i-- )
{
reverse.append(s[i]).append(" ");
}
return reverse.toString();
}
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
System.out.println(reverseString(input));
}
}
2.spring boot working
3.create db for user and group and perform different operations using joins
CREATE TABLE Users (
UserID INT PRIMARY KEY,
UserName VARCHAR(50),
GroupID INT,
FOREIGN KEY (GroupID) REFERENCES Groups(GroupID)
);
-- Create table for groups
CREATE TABLE Groups (
GroupID INT PRIMARY KEY,
GroupName VARCHAR(50)
);
-- Insert sample data into Users table
INSERT INTO Users (UserID, UserName, GroupID)
VALUES
(1, 'Alice', 1),
(2, 'Bob', 2),
(3, 'Charlie', 1),
(4, 'David', 2),
(5, 'Eve', NULL); -- User without a group
-- Insert sample data into Groups table
INSERT INTO Groups (GroupID, GroupName)
VALUES
(1, 'Admins'),
(2, 'Users');
-- Select all users and their corresponding groups
SELECT u.UserName, g.GroupName
FROM Users u
LEFT JOIN Groups g ON u.GroupID = g.GroupID;
-- Select all users who belong to the 'Admins' group
SELECT u.UserName
FROM Users u
JOIN Groups g ON u.GroupID = g.GroupID
WHERE g.GroupName = 'Admins';
-- Select all groups that the user 'Alice' belongs to
SELECT g.GroupName
FROM Users u
JOIN Groups g ON u.GroupID = g.GroupID
WHERE u.UserName = 'Alice';
4.concurrent threads : multitread
5.rest api operations using postman
6.reverse the words in the string Java code"
"1) Difference between == and equals()
2) hash map and concurrent hash map
Use HashMap when you need a non-thread-safe map implementation for single-threaded
or thread-safe environments with external synchronization. allow 1 null key and multiple null values
Use ConcurrentHashMap when you need a thread-safe map implementation for highly
concurrent environments without the need for external synchronization. It's suitable
for scenarios where multiple threads read and write to the map concurrently. not allow null key and values
3) how will you store values in multithreading
concuurenthashmap,copyonwriteArraylist (use thread safe data structures to store)
4) question on hibernate relations
@ManyToOne, @OneToMany, @OneToOne, and @ManyToMany annotations.
5) spring annotations
6) spring boot version lates Spring Boot 2.7.3.
7) question on transaction
8) to create a custom filter, similar to stream filter
@FunctionalInterface
public interface Filter<T> {
boolean test(T element);
}
import java.util.ArrayList;
import java.util.List;
public class CustomFilter {
public static <T> List<T> filter(List<T> list, Filter<T> filter) {
List<T> result = new ArrayList<>();
for (T element : list) {
if (filter.test(element)) {
result.add(element);
}
}
return result;
}
}
Questions were asked based on the skill set given in the resume"
"Javascript:
Hoisting
Closures
Event Loop
Let,Const & Var
Promises, Async & await
React:
Life Cycle Methods in class and Functional Components
How unmounting phase executes in Functional Components
Fetch data from dummy API and display it and filtering same data by input data"
"1) given an array find the repetitive and missing element
Eg:[1,2,2,3,5]
Here 2 is repetitive and 4 is missing
import java.util.*;
import java.lang.*;
class main{
public static int repEle(int [] arr, int n)
{
for(int i=1;i<n;i++)
if(arr[i]==arr[i-1])
return arr[i];
return 0;
}
public static int misEle(int [] arr, int n)
{
int naturalNosum =(n*(n+1))/2;
int sum=arr[0];
for(int i=1;i<n;i++)
{
if(arr[i]==arr[i-1])
continue;
sum+=arr[i];
}
return naturalNosum-sum;
}
public static void main (String[] args) {
//Scanner sc = new Scanner(System.in);
int [] arr = {1,2,2,4,5,6};
int n= arr.length;
System.out.println(repEle(arr,n));
System.out.println(misEle(arr,n));
}
}
using leanear search, hash[arr[i]++],and xor can do as well
---------
2)what is synchronous method synchronous block and why do we need them?
3) reverse a LinkedIn list
class Solution {
public ListNode reverseList(ListNode head) {
ListNode curr = head;
ListNode prev = null;
ListNode next = null;
while(curr != null)
{
next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
}
Spring questions
4) what is dependancy injection and inversion of control?
5) @Value annotation
The @Value annotation provides a convenient way to inject property values into Spring beans, allowing for externalized configuration and easier management of application properties.
6) little bit about Kafka
7) db questions -
There is employee table with name, id, manager, date of joining
Salary table with employee id, salary, variable pay
A) query all employees who joined in the year 2022
B) query employee and salary details even though salary data is not present
C) select all employees who are also managers"
"Coding Round:
This round has two questions and you are expected to give the working code
Q1: Problem statement: (Choose any language of your choice)
Time limit: ~ 60 mins
Implement a catalog of mobiles which have the following attributes - [ModelName, BrandName, LaunchYear, OperatingSystem, Price, Count (sold)]
Implement the following APIs
addMobileToCatalog(Mobile)
Input: addMobileToCatalog({""modelName"": ""Samsung Galaxy A02s"",""brandName"": ""Samsung"",""launchYear"": 2020,""operatingSystem"": ""Android"",""price"": 13000,""count"": 100})
Output: {""statusCode"": 200,""response"": {""modelName"": ""Samsung Galaxy A02s"",""brandName"": ""Samsung"",""launchYear"": 2020,""operatingSystem"": ""Android"",""price"": 13000,""count"": 100}
searchMobile - b…
Mobile Class:
Define a Mobile class with attributes modelName, brandName, launchYear, operatingSystem, price, and count.
java
Copy code
public class Mobile {
private String modelName;
private String brandName;
private int launchYear;
private String operatingSystem;
private double price;
private int count;
// Constructor, getters, and setters
}
CatalogService Interface:
Define a CatalogService interface with methods for adding a mobile to the catalog and searching for mobiles.
java
Copy code
public interface CatalogService {
Mobile addMobileToCatalog(Mobile mobile);
List<Mobile> searchMobile(String brandName, int minPrice, int maxPrice);
// Other methods as needed
}
CatalogServiceImpl Class:
Implement the CatalogService interface in a CatalogServiceImpl class.
java
Copy code
@Service
public class CatalogServiceImpl implements CatalogService {
private List<Mobile> mobileCatalog = new ArrayList<>();
@Override
public Mobile addMobileToCatalog(Mobile mobile) {
mobileCatalog.add(mobile);
return mobile;
}
@Override
public List<Mobile> searchMobile(String brandName, int minPrice, int maxPrice) {
List<Mobile> result = new ArrayList<>();
for (Mobile mobile : mobileCatalog) {
if (mobile.getBrandName().equals(brandName) &&
mobile.getPrice() >= minPrice && mobile.getPrice() <= maxPrice) {
result.add(mobile);
}
}
return result;
}
}
Controller Class:
Create a controller class to handle HTTP requests and map them to corresponding service methods.
java
Copy code
@RestController
@RequestMapping("/api/mobiles")
public class MobileCatalogController {
@Autowired
private CatalogService catalogService;
@PostMapping("/add")
public ResponseEntity<Mobile> addMobileToCatalog(@RequestBody Mobile mobile) {
Mobile addedMobile = catalogService.addMobileToCatalog(mobile);
return new ResponseEntity<>(addedMobile, HttpStatus.OK);
}
@GetMapping("/search")
public ResponseEntity<List<Mobile>> searchMobile(
@RequestParam("brandName") String brandName,
@RequestParam("minPrice") int minPrice,
@RequestParam("maxPrice") int maxPrice) {
List<Mobile> mobiles = catalogService.searchMobile(brandName, minPrice, maxPrice);
return new ResponseEntity<>(mobiles, HttpStatus.OK);
}
}
Sample Request/Response:
You can use tools like Postman to send HTTP requests to your APIs.
Sample Request:
css
Copy code
POST /api/mobiles/add
Body:
{
"modelName": "Samsung Galaxy A02s",
"brandName": "Samsung",
"launchYear": 2020,
"operatingSystem": "Android",
"price": 13000,
"count": 100
}
Sample Response:
json
Copy code
{
"modelName": "Samsung Galaxy A02s",
"brandName": "Samsung",
"launchYear": 2020,
"operatingSystem": "Android",
"price": 13000,
"count": 100
}
----------------------------------------------------
[2:34 pm, 12/03/2024] Mirunalini Wissen Technology: 1:
Write code for Snake and Ladder program for below requirements
Create 2 players
Player1
Player2
Create 2 snakes
snakes.add(99, 9);
snakes.add(30, 3);
Create 2 ladders
ladders.add(5, 25);
ladders.add(13, 95);
Ask candidate to hard-code dice to give 5 as output
First roll would take 1st ladder 0 => 5 ⇒ 25
Second roll would take 2nd snake 25 => 30 ⇒ 3
Third roll is normal move 3 => 8
Fourth roll 2nd ladder. 8 => 13 ⇒ 95
Fifth roll results in a win. 95 => 100
As a negative case change dice hard-code to 6 after step 4th (player at 95) to test new position going beyond 100 (i.e. 95 + 6 = 101)
import java.util.HashMap;
import java.util.Map;
public class SnakeAndLadderGame {
private static final int WINNING_POSITION = 100;
private static final int DICE_ROLL_5 = 5;
private static final int DICE_ROLL_6 = 6;
private static final Map<Integer, Integer> snakes = new HashMap<>();
private static final Map<Integer, Integer> ladders = new HashMap<>();
static {
snakes.put(99, 9);
snakes.put(30, 3);
ladders.put(5, 25);
ladders.put(13, 95);
}
private static int player1Position = 0;
private static int player2Position = 0;
public static void main(String[] args) {
playGame();
}
private static void playGame() {
int rollNumber = 1;
while (true) {
System.out.println("Roll number: " + rollNumber);
// Hard-coded dice roll to give 5 as output
int diceRoll = (rollNumber == 4) ? DICE_ROLL_5 : (rollNumber == 5) ? DICE_ROLL_6 : rollDice();
System.out.println("Dice roll: " + diceRoll);
if (rollNumber % 2 != 0) {
player1Position = movePlayer(player1Position, diceRoll);
if (player1Position == WINNING_POSITION) {
System.out.println("Player 1 wins!");
break;
}
} else {
player2Position = movePlayer(player2Position, diceRoll);
if (player2Position == WINNING_POSITION) {
System.out.println("Player 2 wins!");
break;
}
}
rollNumber++;
System.out.println();
}
}
private static int movePlayer(int currentPosition, int diceRoll) {
int newPosition = currentPosition + diceRoll;
// Check if the new position is a snake or ladder
if (snakes.containsKey(newPosition)) {
newPosition = snakes.get(newPosition);
System.out.println("Got bitten by a snake! Moved to position: " + newPosition);
} else if (ladders.containsKey(newPosition)) {
newPosition = ladders.get(newPosition);
System.out.println("Climbed up a ladder! Moved to position: " + newPosition);
} else {
System.out.println("Normal move. Moved to position: " + newPosition);
}
// Ensure the position does not exceed the winning position
return Math.min(newPosition, WINNING_POSITION);
}
private static int rollDice() {
// Hard-coded dice roll to give random number between 1 to 6
return (int) (Math.random() * 6) + 1;
}
}
------------------------------------
2: Given an array arr of integers, check if there exist two indices i and j such that :
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
Example 1:
Input: arr = [10,2,5,3]
Output: true
Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j]
Example 2:
Input: arr = [3,1,7,11]
Output: false
Explanation: There is no i and j that satisfy the conditions.
ublic class CheckDouble {
public static boolean checkIfExist(int[] arr) {
HashSet<Integer> set = new HashSet<>();
for (int num : arr) {
// Check if 2*num or num/2 exists in the set
if (set.contains(2 * num) || (num % 2 == 0 && set.contains(num / 2))) {
return true;
}
// Add the current number to the set
set.add(num);
}
return false;
}
-----------------------------------------------------------------------
3: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.
Example 1:
Input: s = ""()""
Output: true
Example 2:
Input: s = ""()[]{}""
Output: true
Example 3:
Input: s = ""(]""
Output: false
4: Move all negative numbers to beginning and positive to end with constant extra space
Example:
input: [-1,6,-4,8,-9]
output: [-1,-4,-9,6,4]
5: Array sld contain either half of an number or doublr
Example 1:
Input: s = [1,2,4,8]
Output: true
Example 2:
Input: s = [1,2,3,4]
Output: false
"
[2:34 pm, 12/03/2024] Mirunalini Wissen Technology: "Your aim is to build a console application for a books platform where users can register, purchase and read books.
You need to provide following options:
Register, Login and LogOut: A user can sign up and login (No need for Authentication, name can be considered as id of the user). Login makes users active and logout makes them inactive.
AddBook: Add a book to the collection of books. This operation can only be done by the admin user (which is a part of your application and is not needed to be registered).
Purchase: Users can purchase a book post login.
StartRead/ResumeRead: Users can start reading a book and can resume from where they left off (both start and resume functions the same way).
Next: Once a user is reading a book, he/she can turn to the next p…
[2:34 pm, 12/03/2024] Mirunalini Wissen Technology: "Q1: String s = ""i like coding""
output = ""coding like i""
Q2: singleton design pattern implementation
Q3:inheritance ,overloading , overriding ,static ,synchronized keyword
Q4:joins
Q5:Projects"
Coding question was there
Asked about projects in details
Remove duplicates from a sorted list of integer array
Again twisted the same question in another way nd told to solve"
1. Complete walkthrough on the implemented project assignment.
2. Modifications were also discussed on few APIs.
3. Discussed bonus API methods, if implemented.
3. From Resume, which DB I've worked with, what objects I've worked with & my competency on them.
1. Springboot MVC, @Transactional,
2. RDBMS & two table join query
3. Situation based questions like openion on working off hrs and deadlines, Relocation, etc
Comments
Post a Comment