├── .gitignore ├── DBS ├── DBSBootcamp │ ├── Day-01 │ │ ├── Integer_Caching.png │ │ ├── Java_Method_Behavior.png │ │ ├── P1.java │ │ ├── P2.java │ │ ├── Quiz1Concepts.md │ │ └── quiz1.txt │ └── Day-02 │ │ ├── Test.java │ │ └── P3.java ├── OA_24th_March_2025 │ ├── Coding_BST.md │ ├── Coding_Account.md │ └── mcqs.md ├── Round2_Technical │ └── review_questions.md └── sample_interview_questions.md ├── Vivnovation └── Round 1 │ └── Interview Questions.txt ├── Salesforce ├── Round2 │ └── InterviewQuestions.txt └── Round1 │ └── InterviewQuestions.txt ├── Darwin Box ├── Round2_OA_Questions │ ├── Q1.txt │ └── Q2.txt └── Round1_OA_Questions │ ├── Cyclic_Sequence.java │ ├── Merge_Intervals.java │ └── Minimum_Expression.java ├── Caspex └── Coding │ ├── GroupCounter.java │ ├── DigitalClock.java │ ├── MaxEven.java │ ├── Anagrams.java │ └── Old Questions │ ├── MCQ's.txt │ ├── P1.java │ ├── Character_Retain.java │ └── programming questions.txt ├── RealPage ├── Coding │ ├── BananaRemover.java │ └── MaxSameDigitSum.java ├── Old Questions │ ├── Real Page Coding Questions.txt │ └── realpage questions.txt └── MCQ │ └── MCQ.md ├── EventBrite ├── Last Year Questions │ ├── CachedRequest.java │ ├── MovieRating.java │ └── EventBrite_PreviousYear_Questions.txt ├── InterviewQuestions │ └── Eventbrite_Interview_Questions_README.md └── OA Questions │ ├── oa_questions.md │ └── ServerConnections.java ├── OffCampus ├── TVSEpic │ └── Coding │ │ ├── MagicSwapWizards.cpp │ │ ├── MaxFromReversedDigits.java │ │ └── Maximize_Graph_Score_By_Removing_Edges.java └── Codevita │ └── Zone2 │ ├── ladder.py │ ├── 3dBox.py │ ├── unogame.py │ ├── makehands.py │ ├── pathfinder.py │ └── foldpaper.py ├── Inncircles └── Round 1 │ └── Coding_Problems.md ├── Verisk └── Round 1 │ └── Aptitude │ ├── verbal.md │ ├── arithmetic.md │ └── logical.md ├── README.md └── OpenText └── Old Questions └── opentext questions.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.class -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-01/Integer_Caching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Viishhnur/kmit-companywise-questions-25-26/HEAD/DBS/DBSBootcamp/Day-01/Integer_Caching.png -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-01/Java_Method_Behavior.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Viishhnur/kmit-companywise-questions-25-26/HEAD/DBS/DBSBootcamp/Day-01/Java_Method_Behavior.png -------------------------------------------------------------------------------- /Vivnovation/Round 1/Interview Questions.txt: -------------------------------------------------------------------------------- 1 | Role - AI/ML Engineer 2 | 3 | A casual HR interview 4 | 5 | - Introduction 6 | - What are the projects you have worked on 7 | - What is your interest in AI 8 | - What are your future plans 9 | - What are the challenges you faced during the projects and how did you overcome them 10 | - Hobbies 11 | - What is your approach for learning a new concept -------------------------------------------------------------------------------- /Salesforce/Round2/InterviewQuestions.txt: -------------------------------------------------------------------------------- 1 | Round 2 - Non technical 2 | 1. How was your round 1 and What did the interviewer ask you 3 | 2. Tell me about yourself 4 | 3. What made you apply to this role 5 | 4. My take on AI 6 | 5. Do you think AI will replace developers 7 | 6. What are your strengths 8 | 7. Where do you think you need to improve 9 | 8. Where do you see yourself in 5 years 10 | 9. What is your ultimate goal in life 11 | 10. Before ending the interview, asked her a few questions. -------------------------------------------------------------------------------- /Darwin Box/Round2_OA_Questions/Q1.txt: -------------------------------------------------------------------------------- 1 | Given an array of words, calculate the total number of distinct permutations possible by rearranging the characters of each word individually, and then multiplying the permutation counts of all words. 2 | 3 | Example: 4 | Input: ["too", "hot"] 5 | 6 | For "too": 7 | Total characters = 3 8 | Repeated character 'o' occurs 2 times 9 | Permutations = 3! / 2! = 6 / 2 = 3 10 | 11 | For "hot": 12 | All characters are distinct 13 | Permutations = 3! = 6 14 | 15 | Total permutations = 3 × 6 = 18 16 | -------------------------------------------------------------------------------- /Caspex/Coding/GroupCounter.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | // Question: 4 | // Divide an array into groups such that the difference between 5 | // any two elements in a set is 1. Count the number of such sets. 6 | // 7 | // Example: 8 | // Input: arr = {2, 1, 11, 3} 9 | // Valid sets: {1, 2, 3}, {11} 10 | // Output: 2 11 | public class GroupCounter { 12 | 13 | 14 | public static int countGroups(int[] arr) { 15 | if (arr.length == 0) return 0; 16 | 17 | Arrays.sort(arr); // Sort the array 18 | 19 | int groups = 1; // At least one group 20 | for (int i = 1; i < arr.length; i++) { 21 | if (arr[i] - arr[i - 1] > 1) { 22 | // Start a new group if difference > 1 23 | groups++; 24 | } 25 | } 26 | return groups; 27 | } 28 | 29 | public static void main(String[] args) { 30 | int[] arr = {2, 1, 11, 3}; 31 | int result = countGroups(arr); 32 | System.out.println("Number of valid sets: " + result); // Output: 2 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Darwin Box/Round2_OA_Questions/Q2.txt: -------------------------------------------------------------------------------- 1 | You are given n subtrees, each with 1 to 3 nodes, represented as arrays of the form [root, left, right], where -1 indicates a null child. 2 | 3 | Your task is to merge all the subtrees into a single Binary Search Tree (BST) by performing the following operation repeatedly: 4 | 5 | Choose two distinct subtree indices i and j (i ≠ j) 6 | 7 | The leaf node (either left or right) of the subtree at index i must match the root node of the subtree at index j 8 | 9 | If such a match exists, remove the matching leaf node from subtree i, and attach the subtree at j in its place 10 | 11 | The merge must preserve the BST property 12 | 13 | Repeat this process until all subtrees are merged into a single BST 14 | 15 | Example Input: 16 | 17 | csharp 18 | Copy 19 | Edit 20 | [ 21 | [2, 1, -1], 22 | [3, 2, -1], 23 | [5, 1, 4] 24 | ] 25 | Merging Process: 26 | 27 | Subtree [3, 2, -1] has leaf 2 which is the root of [2, 1, -1] → Merge 28 | 29 | Subtree [5, 1, 4] has leaf 1, which is in merged tree → Merge 30 | 31 | Final BST structure satisfies BST rules 32 | 33 | Expected Output : 34 | 3 2 5 1 4 -------------------------------------------------------------------------------- /Caspex/Coding/DigitalClock.java: -------------------------------------------------------------------------------- 1 | // Given a string consisting only of digits (e.g., "1210"), each digit represents a number displayed on a 7-segment digital display. Your task is to write a Java program that calculates the total number of segments used to display all digits in the string. 2 | 3 | import java.util.*; 4 | public class DigitalClock { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | System.out.print("Enter a string of digits: "); 8 | String input = sc.nextLine(); 9 | 10 | // Array representing the number of segments for each digit from 0 to 9 11 | int[] segments = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; 12 | 13 | int totalSegments = 0; 14 | 15 | // Calculate the total number of segments 16 | for (char c : input.toCharArray()) { 17 | if (Character.isDigit(c)) { 18 | totalSegments += segments[c - '0']; 19 | } else { 20 | System.out.println("Invalid character: " + c); 21 | } 22 | } 23 | 24 | System.out.println("Total segments used: " + totalSegments); 25 | 26 | sc.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Salesforce/Round1/InterviewQuestions.txt: -------------------------------------------------------------------------------- 1 | Round 1 - Technical 2 | 1. Tell me about yourself. 3 | 2. Asked me about one of my projects. 4 | 3. ER diagram for a hospital management system - Asked me to draw it on HackerRank CodePair. 5 | 4. Follow-up questions: 6 | - How would I develop the HMS application using the ER diagram? 7 | - What kind of UI would I build? 8 | - How would I design the backend? 9 | - How would I do authentication? 10 | - How would I implement role-based access? 11 | 5. OOPS - Abstract Classes vs Interfaces. 12 | 6. Design Patterns in Java. 13 | 7. Microservices Architecture. 14 | 8. Asked me if I have knowledge of RDBMS and how I used SQL in my projects. 15 | 9. Asked me to explain one of my other recent projects and follow-up questions: 16 | - Why I used a specific tech stack over others. 17 | - Asked to explain key features of the tech stacks I used. 18 | - Where did I deploy my projects? 19 | 10. How would I optimize the performance of a website? 20 | 11. What is lazy loading? 21 | 12. How did you use AI in your projects? 22 | 13. Binary Search Tree implementation from scratch. 23 | 14. Before ending the interview, she asked me if I had any questions - I asked her one question regarding the company. -------------------------------------------------------------------------------- /RealPage/Coding/BananaRemover.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ❓ Question: 3 | * 4 | * You are given a string S consisting of only uppercase English letters. 5 | * In one move, you can remove a set of characters forming the word "BANANA". 6 | * To form "BANANA", you need: 7 | * - 1 'B' 8 | * - 3 'A's 9 | * - 2 'N's 10 | * 11 | * Characters can appear in any order. 12 | * 13 | * Return the maximum number of times the word "BANANA" can be removed from the string. 14 | * 15 | * 🔹 Example: 16 | * Input: "NAABXXAN" 17 | * Output: 1 // After removing BANANA once, we get "XX" 18 | */ 19 | 20 | public class BananaRemover { 21 | 22 | public static int maxBananaRemovals(String S) { 23 | int countA = 0, countB = 0, countN = 0; 24 | 25 | for (char ch : S.toCharArray()) { 26 | if (ch == 'A') countA++; 27 | else if (ch == 'B') countB++; 28 | else if (ch == 'N') countN++; 29 | } 30 | 31 | return Math.min(countB, Math.min(countA / 3, countN / 2)); 32 | } 33 | 34 | public static void main(String[] args) { 35 | String input = "NAABXXAN"; 36 | int result = maxBananaRemovals(input); 37 | System.out.println("Max BANANA removals: " + result); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Caspex/Coding/MaxEven.java: -------------------------------------------------------------------------------- 1 | // "Max Numbers to Make the Sum Even" 2 | 3 | // You are given a list of positive integers. You must select the maximum number of integers from the list such that their total sum is even. 4 | 5 | // Write a program to return this maximum count of numbers that can be selected. 6 | 7 | import java.util.*; 8 | public class MaxEven { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | System.out.print("Enter the number of integers: "); 12 | int n = sc.nextInt(); 13 | 14 | int[] numbers = new int[n]; 15 | System.out.println("Enter the integers:"); 16 | for (int i = 0; i < n; i++) { 17 | numbers[i] = sc.nextInt(); 18 | } 19 | 20 | int countOdd = 0; 21 | 22 | for (int num : numbers) { 23 | if (num % 2 != 0) { 24 | countOdd++; 25 | } 26 | } 27 | 28 | if (countOdd % 2 == 0) { 29 | // If the count of odd numbers is even, we can take all numbers 30 | System.out.println("Maximum count of numbers with even sum: " + n); 31 | } else { 32 | // If the count of odd numbers is odd, we must exclude one odd number 33 | System.out.println("Maximum count of numbers with even sum: " + (n - 1)); 34 | } 35 | 36 | sc.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Darwin Box/Round1_OA_Questions/Cyclic_Sequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | Samraj loves to play with numbers. Somebody gave him some numbers and he wishes 3 | to play a game with them. 4 | There are 3 operations that have to be applied periodically on the given set of numbers. 5 | 6 | The operations to be applied in periodic manner are (bitwise) XOR, ADD, (bitwise) OR. 7 | 8 | Suppose there are five numbers. Operations will be applied in the following manner: 9 | (((a₁ XOR a₂) + a₃) OR a₄) XOR a₅ 10 | 11 | and it will go on further for more numbers in the same periodic fashion (XOR → ADD → OR → XOR → …). 12 | 13 | You have to predict whether the maximum value possible by applying those operations 14 | cyclically on any chosen subsequence of the given set (order preserved) is Odd or Even. 15 | 16 | NOTE: The sequencing of the numbers in the chosen subsequence is preserved from the main set. 17 | 18 | Input Format: 19 | ------------- 20 | The first line consists of an integer T, the number of test cases. 21 | Then follow T test cases. 22 | - Each test case begins with an integer N, the length of the array. 23 | - Then N integers A₁, A₂, …, Aₙ follow (on one line), the elements of the array. 24 | 25 | Output Format: 26 | -------------- 27 | For each test case, print in a new line Even (without quotes) or Odd (without quotes), 28 | according to the parity of the maximum achievable result. 29 | 30 | Sample Input: 31 | ------------- 32 | 2 33 | 5 34 | 4 5 6 7 8 35 | 4 36 | 1 2 3 4 37 | 38 | Sample Output: 39 | -------------- 40 | Odd 41 | Even 42 | 43 | 44 | Constraints: 45 | ------------ 46 | 1 ≤ T ≤ 10 47 | 1 ≤ N ≤ 10^6 48 | 0 ≤ A[i] ≤ 10^5 49 | 50 | */ 51 | public class Cyclic_Sequence { 52 | 53 | } 54 | -------------------------------------------------------------------------------- /DBS/OA_24th_March_2025/Coding_BST.md: -------------------------------------------------------------------------------- 1 | # DBS OA Coding Question 2 - BST Queries 2 | 3 | ## Problem Statement 4 | 5 | You are given Q queries in the form of 2D array `queries` of size Q × 2. 6 | You have to implement a binary search tree and apply these Q queries to it. 7 | Each query is of the form [X, Y]. 8 | 9 | - If X = 0, insert Y into the binary search tree. 10 | - If X = 1, tell if Y exists in the binary search tree or not. 11 | - If it does, remove Y from the tree. 12 | - If it does NOT exist, print 0. 13 | - If it exists, print 1 and remove it. 14 | 15 | ### Input Format 16 | ``` 17 | Q 18 | Q lines with two space-separated integers: X Y 19 | ``` 20 | 21 | ### Output Format 22 | 23 | For each query where X = 1: 24 | - Print 1 if Y exists in the tree and remove it. 25 | - Print 0 otherwise. 26 | 27 | ### Constraints 28 | - 1 ≤ Q ≤ 10⁵ 29 | - 0 ≤ queries[i][0] ≤ 1 30 | - 1 ≤ queries[i][1] ≤ 10⁴ 31 | 32 | ### Sample Input 33 | ``` 34 | 5 35 | 0 1 36 | 1 1 37 | 1 1 38 | 0 2 39 | 1 2 40 | ``` 41 | 42 | ### Sample Output 43 | ``` 44 | 1 45 | 0 46 | 1 47 | ``` 48 | 49 | ## Solution (Java) 50 | ```java 51 | int[] solve(int Q, int[][] queries) { 52 | Set seen = new HashSet<>(); 53 | List res = new ArrayList<>(); 54 | 55 | for (int[] q : queries) { 56 | int x = q[0], val = q[1]; 57 | if (x == 0) { 58 | seen.add(val); 59 | } else { 60 | if (seen.contains(val)) { 61 | res.add(1); 62 | seen.remove(val); 63 | } else { 64 | res.add(0); 65 | } 66 | } 67 | } 68 | 69 | return res.stream().mapToInt(i -> i).toArray(); 70 | } 71 | ``` 72 | -------------------------------------------------------------------------------- /Caspex/Coding/Anagrams.java: -------------------------------------------------------------------------------- 1 | /* 2 | Question: Check if two strings are anagrams. 3 | 4 | Two strings are said to be anagrams if they contain the same characters with the same frequency, 5 | but possibly in a different order. 6 | 7 | Example: 8 | Input: str1 = "listen", str2 = "silent" 9 | Output: true 10 | 11 | Input: str1 = "hello", str2 = "world" 12 | Output: false 13 | */ 14 | 15 | import java.util.Arrays; 16 | 17 | public class Anagrams { 18 | 19 | // Method 1: Using sorting 20 | public static boolean isAnagram(String str1, String str2) { 21 | // Remove white spaces and convert to lowercase for case-insensitive comparison 22 | str1 = str1.replaceAll("\\s", "").toLowerCase(); 23 | str2 = str2.replaceAll("\\s", "").toLowerCase(); 24 | 25 | // If lengths are different, they can't be anagrams 26 | if (str1.length() != str2.length()) { 27 | return false; 28 | } 29 | 30 | // Convert strings to character arrays and sort them 31 | char[] arr1 = str1.toCharArray(); 32 | char[] arr2 = str2.toCharArray(); 33 | 34 | Arrays.sort(arr1); 35 | Arrays.sort(arr2); 36 | 37 | // Check if sorted arrays are equal 38 | return Arrays.equals(arr1, arr2); 39 | } 40 | 41 | // Main method to test the function 42 | public static void main(String[] args) { 43 | String str1 = "Listen"; 44 | String str2 = "Silent"; 45 | 46 | if (isAnagram(str1, str2)) { 47 | System.out.println(str1 + " and " + str2 + " are anagrams."); 48 | } else { 49 | System.out.println(str1 + " and " + str2 + " are not anagrams."); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /EventBrite/Last Year Questions/CachedRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | 2. Cached Requests 3 | There are n services numbered from 1 to n in a system, and there are m requests to be processed. 4 | The service in which the iᵗʰ request is cached is denoted by cache[i], for all 1 ≤ i ≤ m. 5 | For any request, If the request is processed from its cached service, it takes 1 unit of time. Otherwise, it takes 2 units of time. 6 | 7 | Different services can process different requests simultaneously, but one service can only process one request at a time. Find the minimum time to process all the requests by allocating each request to a service. 8 | 9 | Example 10 | It is given that n = 3, m = 5, and cache = [1, 1, 3, 1, 1]. 11 | If the 1st, 2nd, and 4th requests are assigned to the 1st service, it will take 1 unit of time each, or 3 units of time to process them in total. 12 | Assign the 3rd request to the 2nd service and the 5th request to the 3rd service. It takes 1 and 2 units of time to complete them, respectively. Therefore, all requests are processed in 3 units of time. 13 | 14 | Function Description 15 | Complete the function getMinTime in the editor below. 16 | 17 | getMinTime has the following parameters: 18 | int n: the number of services in the system 19 | int cache[m]: the service in which the request is cached (of length m) 20 | 21 | Returns 22 | int: the minimum time required to process all requests 23 | 24 | Constraints 25 | 1 ≤ n, m ≤ 2 * 10⁵ 26 | 1 ≤ cache[i] ≤ n 27 | 28 | Sample Case 0 29 | Input 30 | n = 4 31 | cache = [1, 2, 3, 4] 32 | Output 33 | 1 34 | 35 | Explanation 36 | Each request is cached in a different service. Process all of them at once, which takes 1 unit of time. 37 | */ 38 | public class CachedRequest { 39 | public static void main(String[] args) { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Caspex/Coding/Old Questions/MCQ's.txt: -------------------------------------------------------------------------------- 1 | MCQ's 2 | 3 | 1.Which of the below are characteristic of cloud? 4 | 5 | i) On premises server room 6 | ii) High availability & reliability 7 | iii) Highly scalable 8 | iv) Multi-sharing 9 | 10 | A)only (III) 11 | B)Only (I) and (II) 12 | C)only (II),(III) and (IV) 13 | D)Only (I) 14 | 15 | 16 | 2. What will be the return value of the below given function if it is called as test(10,20,30) 17 | 18 | int test(int i,int j, int k) 19 | { 20 | if ((i>=j) && (K=j) 24 | return test(i,k,j); 25 | else 26 | return test(j,i,k); 27 | } 28 | 29 | 30 | A)10 31 | B)Garbage Value 32 | C)30 33 | D)20 34 | 35 | 36 | 3.what will be the return value of the function given below if called as cal(10) 37 | 38 | 39 | int cal(sum) 40 | { 41 | int f:=1, var := 1, c= s 42 | do 43 | { 44 | f:=f+1 45 | var:=var+f 46 | c:=c+1 47 | }while (var<=sum) 48 | 49 | return c; 50 | } 51 | 52 | A)10 53 | B)15 54 | C)4 55 | D)5 56 | 57 | 58 | 4)When Elastic IPs get charged by AWS to customer? 59 | 60 | A) Elastic IP is a free service 61 | B) None of the given options 62 | C) Only when it is attached to EC2 instance 63 | 64 | 5) Which of the following given statements are true about string class? 65 | 66 | i)Memory allocation for string objects happens dynamically 67 | ii)Memory wastage is more in case of string when compared to character array 68 | iii) string objects are more prone to array decay. 69 | iv)it is easier to implement character array than a string. 70 | 71 | 72 | A)only (i) and (iv) 73 | B)only (i),(ii) and (iii) 74 | C)only (ii) and (iii) 75 | D)only (i),(ii) and (iv) 76 | 77 | 78 | -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-02/Test.java: -------------------------------------------------------------------------------- 1 | public class Test{ 2 | public static void main(String[] args) { 3 | // int x = 5; 4 | // x += x++ + ++x; 5 | // System.out.print(x); // 17 6 | 7 | // int a = 5; 8 | // int b = 10; 9 | // System.out.println(a++ * --b); // 45 10 | 11 | // int x = 5; 12 | // int y = ++x + x++ + --x; // 6 + 6 + 6 (Left to Right Associativity) 13 | // System.out.println(y); // 18 14 | 15 | // String s1 = "OCA"; 16 | // String s2 = "O" + "C" + "A"; 17 | // System.out.println(s1 == s2); 18 | 19 | // System.out.println(10 + 20 + "Java" + 10 + 20); // if one of them is a string then from their everything is treated as a string 20 | 21 | // System.out.println(10 + "Java" + 5*2); 10Java10 22 | // System.out.println(10 + "Java" + 5/2); 10Java2 23 | 24 | // Integer a = 10; 25 | // Integer b = 10; 26 | // Integer c = 200; 27 | // Integer d = 200; 28 | // System.out.println(a == b); // true due to Integer caching from -128 to 127 29 | // System.out.println(c == d); // false 30 | 31 | // Integer a = 10; 32 | // Integer b = new Integer(10); 33 | // System.out.println(a == b); // false since references are compared 34 | // System.out.println(a.equals(b)); // this is true since only values are compared 35 | 36 | // int x = 10; 37 | // int y = 5; 38 | // System.out.println(x > y ? "Greater" : x == y ? "Equal" : "Smaller") ; // Greater 39 | 40 | // int x = 5; 41 | // System.out.println(x > 2 || x++ < 1 / 0); // true -> no exception because this is a short circuit || operator 42 | // System.out.println(x > 2 && x++ < 1 / 0); // Arithmetic Exception because this is a short circuit && operator 43 | // System.out.println(x); 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-01/P1.java: -------------------------------------------------------------------------------- 1 | /* 2 | In a birthday party, there are N guests attended the party. 3 | All of them formed in a circle, each of the guest numbered from 1 to N. 4 | 5 | But we have dinner tokens for only N-1 guests. 6 | and you are given an integer S. 7 | 8 | The distibution of tokens as follows: 9 | 1- Intially you visit guest-1. 10 | 2- Visit to the next S guests in the circle in clockwise direction including 11 | visited guest, you may visit some guests more than once. 12 | 3- The last guest you visit will get the token and moves out of the circle. 13 | 4- You have to repeat the process from step-2, until all the tokens over. 14 | 15 | At the only one guest will be leftout without a token. 16 | 17 | You are given the number of guests, N , and an integer S , 18 | Your task is to find the guest number who haven't recieved the token. 19 | 20 | Input Format: 21 | ------------- 22 | Two integers N and S, number of guests N and value of S. 23 | 24 | Output Format: 25 | -------------- 26 | Print an integer, Guest number remained at the end without a token. 27 | 28 | 29 | Sample Input-1: 30 | --------------- 31 | 5 3 32 | 33 | Sample Output-1: 34 | ---------------- 35 | 4 36 | 37 | 38 | Sample Input-2: 39 | --------------- 40 | 6 2 41 | 42 | Sample Output-2: 43 | ---------------- 44 | 5 45 | 46 | */ 47 | 48 | import java.util.*; 49 | public class P1{ 50 | public static void main(String[] args) { 51 | Scanner sc = new Scanner(System.in); 52 | 53 | int n = sc.nextInt(); 54 | int s = sc.nextInt(); 55 | 56 | List guests = new ArrayList<>(); 57 | for(int i = 1 ; i <= n ; i++){ 58 | guests.add(i); 59 | } 60 | 61 | // Now start from guest 1 62 | int i = 0; 63 | while(guests.size() > 1){ 64 | int nextIdx = (i + s - 1) % guests.size(); 65 | guests.remove(nextIdx); 66 | i = nextIdx ; 67 | } 68 | 69 | System.out.println(guests.get(0)); 70 | 71 | sc.close(); 72 | } 73 | } -------------------------------------------------------------------------------- /RealPage/Coding/MaxSameDigitSum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ❓ Question: 3 | * 4 | * Given an array A consisting of N integers, find the maximum sum of two integers 5 | * from A that have the **same first and last digit**. 6 | * 7 | * Example: 8 | * Input: A = [130, 10, 191, 200, 10] 9 | * Output: 140 10 | * Explanation: The numbers 130 and 10 both have first digit '1' and last digit '0'. 11 | * Their sum is 130 + 10 = 140. 12 | * 13 | * If no such pair exists, return -1. 14 | */ 15 | 16 | import java.util.*; 17 | 18 | public class MaxSameDigitSum{ 19 | 20 | // Helper to get first digit of a number 21 | private static int getFirstDigit(int num) { 22 | num = Math.abs(num); 23 | while (num >= 10) { 24 | num /= 10; 25 | } 26 | return num; 27 | } 28 | 29 | // Helper to get last digit of a number 30 | private static int getLastDigit(int num) { 31 | return Math.abs(num % 10); 32 | } 33 | 34 | public static int maxSumSameFirstLastDigits(int[] A) { 35 | // Map: key = "firstDigit_lastDigit", value = list of numbers with that pattern 36 | Map> map = new HashMap<>(); 37 | 38 | for (int num : A) { 39 | int first = getFirstDigit(num); 40 | int last = getLastDigit(num); 41 | String key = first + "_" + last; 42 | 43 | map.putIfAbsent(key, new ArrayList<>()); 44 | map.get(key).add(num); 45 | } 46 | 47 | int maxSum = -1; 48 | 49 | for (List list : map.values()) { 50 | if (list.size() >= 2) { 51 | // Sort descending to get top two largest numbers 52 | list.sort(Collections.reverseOrder()); 53 | int sum = list.get(0) + list.get(1); 54 | maxSum = Math.max(maxSum, sum); 55 | } 56 | } 57 | 58 | return maxSum; 59 | } 60 | 61 | public static void main(String[] args) { 62 | int[] A = {130, 10, 191, 200, 10}; 63 | int result = maxSumSameFirstLastDigits(A); 64 | System.out.println("Max sum of matching first and last digit pair: " + result); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /OffCampus/TVSEpic/Coding/MagicSwapWizards.cpp: -------------------------------------------------------------------------------- 1 | /* Problem Title: "Magic Swap Wizards – Alice & Bob" 2 | 3 | Problem Statement: 4 | 5 | In the fantastic Land of Swaps, there are two mighty wizards: Alice and Bob. They each have a row of N distinct positive integers. 6 | 7 | One sequence belongs to Alice, the other to Bob. 8 | 9 | It is necessary for the good of the kingdom that both sequences become identical, though initially they may not be the same. 10 | 11 | They can perform the following magical coordinated swaps: 12 | 13 | Alice’s ability: She can choose any two positions i and j in her sequence and swap the elements at those positions. 14 | 15 | Bob’s ability: After Alice's swap, Bob can also perform a similar swap. But he must swap two positions P and Q such that |P - Q| = |i - j|, i.e., 16 | the distance between swapped indices must be the same. 17 | 18 | Using these rules, the goal is to check if Alice and Bob can make both sequences identical. 19 | 20 | Input Format: 21 | 22 | First line: Integer N - size of both sequences 23 | Second line: N space-separated integers - Alice's sequence 24 | Third line: N space-separated integers - Bob's sequence 25 | 26 | Output Format: 27 | 28 | Print "yes" if they can make the sequences equal, otherwise print "no". 29 | 30 | Sample Test Case-1 : 31 | Input: 32 | 5 33 | 1 3 4 2 5 34 | 4 3 5 7 1 35 | 36 | Output: 37 | no 38 | 39 | Sample Testcase 2: 40 | Input: 41 | 4 42 | 1 2 3 4 43 | 4 3 2 1 44 | 45 | Output: 46 | yes 47 | 48 | Constraints: 49 | 50 | 1 ≤ N ≤ 10⁵ 51 | 52 | 1 ≤ A[i], B[i] ≤ 10⁵ 53 | 54 | Sum of N over all test cases ≤ 10⁵ 55 | */ 56 | #include 57 | #include 58 | using namespace std; 59 | 60 | class MagicSwapWizards { 61 | bool canMatch(vector& A, vector& B) { 62 | vector evenA, oddA, evenB, oddB; 63 | for (int i = 0; i < A.size(); ++i) { 64 | if (i % 2 == 0) { 65 | evenA.push_back(A[i]); 66 | evenB.push_back(B[i]); 67 | } else { 68 | oddA.push_back(A[i]); 69 | oddB.push_back(B[i]); 70 | } 71 | } 72 | sort(evenA.begin(), evenA.end()); 73 | sort(evenB.begin(), evenB.end()); 74 | sort(oddA.begin(), oddA.end()); 75 | sort(oddB.begin(), oddB.end()); 76 | 77 | return evenA == evenB && oddA == oddB; 78 | } 79 | 80 | }; 81 | -------------------------------------------------------------------------------- /DBS/OA_24th_March_2025/Coding_Account.md: -------------------------------------------------------------------------------- 1 | # DBS OA Coding Question 1 - Account Information Filter 2 | 3 | ## Problem Statement 4 | 5 | Find out the following information about accounts that you transact with through your digital wallet. Based on the user's input information, this information must be in increasing order of bank account numbers. 6 | 7 | ### Input Format 8 | 9 | - The first line contains a single integer `N`, denoting the number of saved accounts. 10 | - Each of the next `N` lines contains 5 strings denoting saved account information: 11 | 1. `account_number` 12 | 2. `account_holder_first_name` 13 | 3. `account_holder_last_name` 14 | 4. `registered_mobile_number` 15 | 5. `branch_code` 16 | - The next line contains a string `D` denoting the name of the information the user has. 17 | - The last line contains a string `V` denoting the value of the user's information. 18 | 19 | ### Output Format 20 | 21 | Print all the information of the accounts in increasing order of `account_number` where the given field `D` has the value `V`. 22 | 23 | ### Constraints 24 | 25 | - 1 ≤ N ≤ 1000 26 | - 1 ≤ A[i][j] ≤ 15 27 | - All fields contain only lowercase letters and numbers. 28 | 29 | ### Sample Input 30 | ``` 31 | 3 32 | 1122199312 rohan garg 7384728384 1022 33 | 11221909566 shivam kumar 9128494856 1022 34 | 1122139321 shivam sharma 7384728384 1022 35 | account_holder_first_name 36 | shivam 37 | ``` 38 | 39 | ### Sample Output 40 | ``` 41 | 1122139321 shivam sharma 7384728384 1022 42 | 11221909566 shivam kumar 9128494856 1022 43 | ``` 44 | 45 | ## Solution (Java) 46 | ```java 47 | String[][] solve(int N, String[][] accounts, String D, String V) { 48 | Map fieldMap = Map.of( 49 | "account_number", 0, 50 | "account_holder_first_name", 1, 51 | "account_holder_last_name", 2, 52 | "registered_mobile_number", 3, 53 | "branch_code", 4 54 | ); 55 | 56 | int idx = fieldMap.get(D); 57 | int cnt = 0; 58 | 59 | for (String[] account : accounts) { 60 | if (account[idx].equals(V)) { 61 | cnt++; 62 | } 63 | } 64 | 65 | String[][] res = new String[cnt][5]; 66 | int ind = 0; 67 | for (String[] account : accounts) { 68 | if (account[idx].equals(V)) { 69 | res[ind++] = account; 70 | } 71 | } 72 | 73 | Arrays.sort(res, Comparator.comparing(acc -> acc[0])); 74 | return res; 75 | } 76 | ``` 77 | -------------------------------------------------------------------------------- /Inncircles/Round 1/Coding_Problems.md: -------------------------------------------------------------------------------- 1 | # Inncircles Coding Problems 2 | 3 | --- 4 | 5 | ## 1. Extract Hashtag Words 6 | 7 | **Problem Statement:** 8 | 9 | You are given a string. Your task is to return **all words** from the string that: 10 | 11 | - Start with the character `#` 12 | - Contain **only lowercase English alphabets** (a-z) 13 | - Have **more than 3 alphabet characters** (excluding the `#`) 14 | 15 | A valid word must look like this: `#example`, where `example` is lowercase and its length is **at least 4**. 16 | 17 | **Example Input:** 18 | ``` 19 | I love #cats and #dogs but #h also #elephant is cute 20 | ``` 21 | 22 | **Example Output:** 23 | ``` 24 | ["#cats", "#dogs", "#elephant"] 25 | ``` 26 | 27 | --- 28 | 29 | ## 2. Maximum Subarray Sum of Size K 30 | 31 | **Problem Statement:** 32 | 33 | Given an array of integers and an integer `K`, return the **maximum sum** of any **contiguous subarray** of length `K`. 34 | 35 | You must use the **sliding window** technique to ensure linear time complexity. 36 | 37 | **Example Input:** 38 | ```python 39 | arr = [1, 4, 2, 10, 23, 3, 1, 0, 20] 40 | k = 4 41 | ``` 42 | 43 | **Example Output:** 44 | ``` 45 | 39 46 | ``` 47 | 48 | **Explanation:** 49 | The subarray `[4, 2, 10, 23]` has the maximum sum = 39. 50 | 51 | --- 52 | 53 | ## 3. Extract Words by Format 54 | 55 | **Problem Statement:** 56 | 57 | You are given a string that may contain words in the following three formats: 58 | 59 | - **Alpha Format:** 60 | Pattern: `EX-[0-9]{3}-[A-Z]{2}` 61 | Example: `EX-123-AB` 62 | 63 | - **Beta Format:** 64 | Pattern: `[0-9]{3}-[a-z]{3}-[0-9]{2}` 65 | Example: `123-abc-45` 66 | 67 | - **Gamma Format:** 68 | Pattern: `#G:[a-zA-Z]{6}` 69 | Example: `#G:abCDef` 70 | 71 | Return all substrings in the string that match **any** of the above formats. 72 | 73 | **Example Input:** 74 | ``` 75 | The codes are EX-123-AB and 456-def-99 and #G:xyzABC. Another one is #G:12abCD and EX-789-XY. 76 | ``` 77 | 78 | **Example Output:** 79 | ``` 80 | ["EX-123-AB", "456-def-99", "#G:xyzABC", "EX-789-XY"] 81 | ``` 82 | 83 | --- 84 | 85 | ## 4. Operation Frequency Counter 86 | 87 | **Problem Statement:** 88 | 89 | You are given a list (or space-separated string) of **sequential operations** such as `load`, `sleep`, etc. 90 | For each operation, you must print how many times **that particular operation has occurred** up to that point. 91 | 92 | **Example Input:** 93 | ``` 94 | load sleep load 95 | ``` 96 | 97 | **Example Output:** 98 | ``` 99 | 1 1 2 100 | ``` 101 | 102 | **Explanation:** 103 | - First `load` → count becomes 1 104 | - Then `sleep` → count becomes 1 105 | - Then another `load` → count becomes 2 -------------------------------------------------------------------------------- /EventBrite/InterviewQuestions/Eventbrite_Interview_Questions_README.md: -------------------------------------------------------------------------------- 1 | # Eventbrite Interview Questions Compilation 2 | 3 | This document contains a compiled list of Eventbrite interview questions collected from two different candidates(2026 batch). These questions span various technical and behavioral areas and can help in interview preparation. 4 | 5 | --- 6 | 7 | ## 📌 General Questions 8 | 1. Tell me about yourself. 9 | 2. How was the HackerRank test? 10 | 11 | --- 12 | 13 | ## 🧠 Technical Questions 14 | 15 | ### 📊 Projects & Technology Choices 16 | - In your project why did you use MongoDB? Compare it with SQL. What would be your choice now? 17 | - Explain about semantic search / vector search. 18 | - What is RAG (Retrieval-Augmented Generation)? Why would you use it? 19 | 20 | ### ☁️ Cloud and DevOps 21 | - What are Cloud Functions? Why are they used? 22 | - Where do you use Jenkins? 23 | - Why do we prefer cloud computing? 24 | 25 | ### 🐍 Python & Environments 26 | - Have you used Virtual environments in Python? How do they differ from Docker? 27 | - Python environment vs Docker image difference. 28 | 29 | ### 🌐 Frameworks & Libraries 30 | - FastAPI vs Flask vs Django. 31 | - Tell me what is Tailwind CSS? 32 | 33 | --- 34 | 35 | ## 📚 Database Questions 36 | 37 | ### Tables: 38 | - Table 1: id, name, dept, salary 39 | - Table 2: dept, dept perks 40 | 41 | #### Queries: 42 | 1. Find the name and salary of the employee earning the maximum salary in each department. 43 | 2. Find the name and department perks for each employee. 44 | 45 | --- 46 | 47 | ## 📈 Coding & DSA 48 | 49 | ### DP 50 | - Write DP pseudocode. 51 | 52 | ### Stock Profit Maximization 53 | - You are given an array of stock prices of upcoming days. 54 | - You can buy and sell only one stock at a time. 55 | - How would you maximize the total profit made by the end? 56 | 57 | --- 58 | 59 | ## ➗ Aptitude 60 | - There are 10 teams in IPL. Each team plays 2 matches with all other teams. 61 | - How many matches are possible? 62 | 63 | --- 64 | 65 | ## ⚙️ OOPs & System Design 66 | - What are the differences between overloading and overriding? 67 | - Give a real-life case usage of overloading and overriding. 68 | - My shape design game related questions (including deployment and GitHub). 69 | 70 | --- 71 | 72 | ## 🧍 Behavioral Questions 73 | - Family, address, EAMCET rank, why CSE? 74 | - What are your strengths and weaknesses? 75 | - Which domain is your interest? 76 | - If a team member disagrees with you, what would you do? 77 | - If a member in the team is not working, what would you do? 78 | - If there is a deadline, how would you complete the project in time? 79 | 80 | --- 81 | 82 | ## ❓ Closing 83 | - Do you have any questions? 84 | 85 | --- 86 | 87 | This document was compiled for interview preparation based on real candidate experiences with Eventbrite. 88 | -------------------------------------------------------------------------------- /OffCampus/Codevita/Zone2/ladder.py: -------------------------------------------------------------------------------- 1 | ''' Ladder Problem 2 | Problem Description 3 | Shyam is tasked with relocating a lengthy ladder within his residence. The substantial presence of various household items throughout the house presents significant challenges when attempting to manoeuvre the ladder through confined areas. 4 | 5 | The house is represented as a grid of M rows and N columns. Each cell in the grid can contain: 6 | 7 | 'l' - part of the current position of the ladder (source). 8 | 'L' - part of the destination where the ladder needs to go. 9 | 'B' - a household item (Block). 10 | 'E' - an empty cell where the ladder can move. 11 | The ladder has a fixed length and is placed either horizontally or vertically in the grid. It must always remain in a straight line unless it is being rotated. 12 | 13 | Movement Rules 14 | The ladder can be moved one cell at a time in any of the four directions (up/down/left/right), maintaining its orientation. 15 | The ladder can be rotated by 90 degrees (from horizontal to vertical or vice versa) only if all cells in the square area formed by both the current and rotated positions are empty (no B or walls). 16 | Each move or rotation counts as 1 step. 17 | Goal is to find the minimum number of steps required to move the ladder from the source ('l') to the destination ('L'). 18 | If it is not possible, print "Impossible". 19 | 20 | Constraints 21 | 0 <= M, N <= 15 22 | 23 | 2 <= Length of ladder <= 6 24 | 25 | Input 26 | First line: Two integers M and N, the dimensions of the grid. 27 | 28 | Next M lines: N space-separated characters representing the grid ('l', 'L', 'B', or 'E'). 29 | 30 | Output 31 | A single integer representing the minimum number of steps, or the string "Impossible". 32 | 33 | Time Limit (secs) 34 | 1 35 | 36 | Examples 37 | Example 1 38 | 39 | Input 40 | 41 | 5 5 42 | llEEE 43 | EBEEB 44 | EBEBB 45 | EBEEB 46 | EEELL 47 | 48 | Output 49 | 50 | 8 51 | 52 | Explanation 53 | 54 | The input is diagrammatically represented as depicted below. 55 | 56 | The sequence of diagrams shows the movement of ladder to the required place. 57 | 58 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@3b0f7d9d:image1.png 59 | 60 | After two moves, the ladder occupies a 2x2 area of free cells, allowing it to be rotated. Following this process, the ladder has been moved to its destination in 8 steps, which represents the minimum required. 61 | 62 | Example 2 63 | 64 | Input 65 | 66 | 6 6 67 | lllEEE 68 | EBEEEE 69 | EEEEEE 70 | EEEEBE 71 | EEEEEE 72 | LLLEBE 73 | 74 | Output 75 | 76 | 7 77 | 78 | Explanation 79 | 80 | Below diagrams shows the movement of ladder to the required place. 81 | 82 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@3b0f7d9d:image2.png 83 | 84 | As you can see that 7 steps are required to move the ladder to its destination.''' 85 | -------------------------------------------------------------------------------- /EventBrite/Last Year Questions/MovieRating.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 1. Movie Ratings 4 | Alexa loves movies and maintains a list of negative and/or positive integer ratings for the movies in her collection. She's getting ready for a film festival and wants to choose some subsequence of movies from her collection to bring such that the following conditions are satisfied: 5 | 6 | The collective sum of their ratings is maximal. 7 | 8 | She must go through her list in order and cannot skip more than one movie in a row. 9 | 10 | In other words, she cannot skip over two or more consecutive movies. For example, if 11 | ratings = [1, -3, -2], she must include either the second number or the first and third numbers to get a maximal rating sum of -1. 12 | 13 | Example 14 | If ratings = [-3, 2, 4, -1, -2, -5], 15 | Her maximal choices are [2, 4, -2] for a sum of 4. 16 | 17 | Function Description 18 | Complete the function maximizeRatings in the editor below. The function must return an integer denoting the maximum possible rating sum for Alexa's chosen subsequence of movies without reordering them. 19 | 20 | maximizeRatings has the following parameter(s): 21 | ratings(ratings[0],....ratings[n-1]): an array of integers 22 | 23 | Constraints: 24 | 1 ≤ n ≤ 10⁵ 25 | -1000 ≤ ratings[i] ≤ 1000, where 0 ≤ i < n 26 | 27 | Input 28 | ratings: a list of integers of size n (1 ≤ n ≤ 10⁵) 29 | Each ratings[i] (where 0 ≤ i < n) is in the range -1000 to 1000 30 | 31 | Sample Case 0 32 | Input 33 | 5 34 | 9 35 | -1 36 | -3 37 | 4 38 | 5 39 | 40 | Output 41 | 17 42 | 43 | Explanation 44 | Alexa picks the bolded items in ratings = [9, -1, -3, 4, 5] to get maximum rating: 45 | 9 + 4 + 5 = 17. 46 | Thus, the answer is 17. 47 | */ 48 | import java.util.*; 49 | 50 | public class MovieRating { 51 | 52 | private static int solve(int idx, int[] ratings, final int n, boolean taken) { 53 | if (idx == n) { 54 | return 0; 55 | } 56 | 57 | int take = ratings[idx] + solve(idx + 1, ratings, n, true); 58 | // But you can only notTake if have taken prev 59 | int notTake = Integer.MIN_VALUE; 60 | if (taken) { 61 | notTake = solve(idx + 1, ratings, n, false); 62 | } 63 | 64 | return Math.max(take, notTake); 65 | } 66 | 67 | private static int maximizeRatings(int[] ratings, final int n) { 68 | return solve(0, ratings, n, true); // initially taken is true to allow skipping the first element if needed 69 | } 70 | 71 | public static void main(String[] args) { 72 | try (Scanner sc = new Scanner(System.in)) { 73 | int n = sc.nextInt(); 74 | int[] ratings = new int[n]; 75 | 76 | for (int i = 0; i < n; i++) { 77 | ratings[i] = sc.nextInt(); 78 | } 79 | 80 | System.out.println(maximizeRatings(ratings, n)); 81 | 82 | } catch (Exception e) { 83 | System.out.println(e.getMessage()); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /DBS/Round2_Technical/review_questions.md: -------------------------------------------------------------------------------- 1 | # 📝 DBS Interview Experience – 2025 Batch 2 | 3 | ## 📌 My Interview Experience 4 | 5 | ### 🔹 Questions Asked: 6 | 7 | 1. **Tell me about yourself.** 8 | 2. Since I mentioned **GenAI** in my project: 9 | - What is **Generative AI**? 10 | - Explain your **use case** in the project. 11 | 3. What are the other **technologies** you used in the project? Explain briefly. 12 | 4. What is **DevOps**? 13 | - What are **CI/CD pipelines**? 14 | 5. Explain **OOPS Concepts** with real-time examples. 15 | 6. What is `out` in `System.out.println();` 16 | 7. **Coding Questions:** 17 | - Write a program to **reverse a string**. 18 | - **Swap two numbers** without using a third variable. 19 | 8. Write an **SQL query** using **JOIN** on `emp` and `dept` table. 20 | 9. Write a program to **find duplicates in an array** without using `HashMap`. 21 | 10. **Any questions about the company?** 22 | 23 | --- 24 | 25 | ### ✅ Conclusion (Tips from My Interview) 26 | 27 | - Take time to **understand the question** before jumping into the code. 28 | - **Ask clarifying questions** about constraints, method types, etc. 29 | - Be clear with your **project explanation** and **resume** content. 30 | - Good **presence of mind** is key — not everything is hardcore technical. 31 | 32 | --- 33 | 34 | ## 📚 Friends’ Interview Experiences 35 | 36 | ### 🔹 Common Questions Asked: 37 | - Detailed questions about **projects**. 38 | - **Why did you choose this tech stack?** 39 | - Explain the **workflow** of your project. 40 | - Gave a **simple coding question** (e.g., reverse a string) and asked for **multiple solutions**. 41 | - **Situational question**: 42 | > “If there's a short deadline and a lot of pending work, how would you handle it?” 43 | - If part of any **clubs or committees**, they asked: 44 | - What was your **contribution**? 45 | - What were your **highs and lows**? 46 | 47 | --- 48 | 49 | ## 🔍 Technical Concepts Covered 50 | 51 | - Projects and **Technology Stacks** used 52 | - Real-world examples of **OOPS concepts** 53 | - **DBMS queries** 54 | - Basics of **Python**, **Java** 55 | - **Exception handling** 56 | 57 | --- 58 | 59 | ## 🦈 Shark Tank Style Question 60 | 61 | > "If you were to pitch one of your projects on Shark Tank, which one would you choose and why?" 62 | 63 | --- 64 | 65 | ## 🤖 Framework-Specific Questions 66 | 67 | - Questions about each **framework/tool** used in projects: 68 | - **RAG (Retrieval-Augmented Generation)** 69 | - **Agents** 70 | - Their **functionalities** and **real-time usage** 71 | 72 | --- 73 | 74 | ## 💼 HR Questions 75 | 76 | - If given an offer from **Google vs. DBS**, which would you choose and why? 77 | - “Why DBS if you want to build a startup?” 78 | - “Do you have any questions for us?” 79 | 80 | --- 81 | 82 | ## ✅ Final Thoughts 83 | 84 | > "The interviews were not heavily technical but tested presence of mind, communication, and how well you know your **own work and decisions**." 85 | 86 | --- 87 | 88 | -------------------------------------------------------------------------------- /OffCampus/Codevita/Zone2/3dBox.py: -------------------------------------------------------------------------------- 1 | '''Layout Wrap 2 | Problem Description 3 | In the town of Origamia, people do not use ordinary rectangular sheets to wrap gifts. Instead, they use wrapping sheets that come in a variety of unique shapes and layouts. 4 | 5 | Origamia's gift sheets feature unique rectilinear cuts, such as cross or T-shapes, unlike standard wrapping paper. These layouts are carefully crafted so that, with the right sequence of folds, they can transform into beautiful, closed gift boxes. 6 | 7 | Folding is allowed along the lines which ever passing on the sheet, and each fold must be a precise 90-degree bend, either upwards (a mountain fold) or downwards (a valley fold). If a fold brings two sheet edges together seamlessly, they are airtight and bonded with no gaps. 8 | 9 | The challenge is to determine whether a given sheet layout, with its specific edges, can be folded into a perfectly closed 3D gift box. Some layouts fold into fully closed boxes, while others always leave open flaps or sides. 10 | 11 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@3ad394e6:image1.png 12 | 13 | Constraints 14 | 4 <= N <= 25 15 | 16 | 0 <= x, y <= 25 17 | 18 | Input 19 | The first line contains N, the total number of line segments provided. 20 | 21 | The next N lines each contain four integers separated by spaces, representing the endpoints of a line segment as x1 y1 x2 y2. 22 | 23 | Output 24 | Print a single integer: 25 | 26 | The volume of the box when a closed shape is formed. 27 | Otherwise, print 0. 28 | Time Limit (secs) 29 | 1 30 | 31 | Examples 32 | Example 1 33 | 34 | Input 35 | 36 | 12 37 | 38 | 1 0 2 0 39 | 40 | 2 0 2 5 41 | 42 | 1 0 1 5 43 | 44 | 1 5 2 5 45 | 46 | 0 2 3 2 47 | 48 | 3 2 3 4 49 | 50 | 3 4 0 4 51 | 52 | 0 2 0 4 53 | 54 | 3 4 4 4 55 | 56 | 4 4 4 3 57 | 58 | 4 3 3 3 59 | 60 | 1 1 2 1 61 | 62 | Output 63 | 64 | 2 65 | 66 | Explanation 67 | 68 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@3ad394e6:image2.png 69 | 70 | The input when processed forms a shape as depicted in the diagram. 71 | 72 | It folds into a 1x1x2 cuboid. Hence the volume is 2 and output is 2. 73 | 74 | Example 2 75 | 76 | Input 77 | 78 | 13 79 | 80 | 0 0 2 0 81 | 82 | 2 0 2 1 83 | 84 | 2 1 0 1 85 | 86 | 0 1 0 0 87 | 88 | 2 4 3 4 89 | 90 | 3 4 3 1 91 | 92 | 3 1 2 1 93 | 94 | 2 1 2 4 95 | 96 | 2 0 3 0 97 | 98 | 3 0 3 1 99 | 100 | 1 1 1 0 101 | 102 | 2 2 3 2 103 | 104 | 2 3 3 3 105 | 106 | Output 107 | 108 | 0 109 | 110 | Explanation 111 | 112 | The image below depicts input. 113 | 114 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@3ad394e6:image3.png 115 | 116 | The input when processed forms a shape as depicted in the diagram. 117 | 118 | Folding this sheet results in a cube-like shape with one side left open. 119 | 120 | Therefore, it is unable to form a closed figure, resulting in an output of 0.''' -------------------------------------------------------------------------------- /RealPage/Old Questions/Real Page Coding Questions.txt: -------------------------------------------------------------------------------- 1 | 2 | 1. Can you iterate over elements in a Java HashMap? 3 | 4 | A) No, you cannot 5 | B) Yes, but the order of the element is undefined 6 | C) Yes,and the elements are always sorted by the defined keys 7 | 8 | 2.what is the best way to validate a telephone number in your application 9 | 10 | A) Write your own parser 11 | B) Use a regular expression and check if the result matches your string 12 | C) Parse it as an integer 13 | 14 | 3) What would be a good way of describing streams in Java 8 ? 15 | 16 | A) Streams are processing patterns that work on your data 17 | B) Streams are data structures that store incoming data 18 | C) Streams are APIs for streaming data in your web application (e.g., websockets,video) 19 | 20 | 21 | 4) What would this program output ? 22 | 23 | String value = "red"; 24 | switch(value) { 25 | case "red" : System.out.println("FAIL"); 26 | case "green" : System.out.println("OK"); 27 | } 28 | 29 | A) FAIL OK 30 | B) FAIL 31 | C) It would not compile,as you cannot use switch with strings 32 | 33 | 34 | 5) Is the following assignment to a method parameter valid in Java ? 35 | 36 | void method(int a) { 37 | ... 38 | a=4; 39 | ... 40 | 41 | } 42 | 43 | A) No,it will produce a compile error 44 | B) Yes 45 | 46 | 47 | 6)What is the time complexity of appending an element to an ArrayList ? 48 | 49 | A) Always O(1) 50 | B) Always O(n) 51 | C) Amortized O(1) 52 | 53 | 54 | 7) What is the main purpose of buffered input/output streams ? 55 | 56 | A) To increase performance,as most I/O operations are done in blocks, 57 | B) To be able read/write the same file from many theads at once. 58 | C) It is a security measure against buffer overflows and denial-of-servoce attack 59 | 60 | 61 | 62 | 8) what is the visibility of a class without an access modifier ? 63 | 64 | A) It as same as public 65 | B) It is public if it has the same name as a source file, otherwise it is the same as 66 | C) It is visible within the same package. 67 | 68 | 69 | 9) What is the JAR File Format ? 70 | 71 | A) It is a Java bytecode format 72 | B) It is a platform specific package type that allows applications to be launched. 73 | C) It is a package built on the ZIP Format, aggregating Java class files,metadata 74 | 75 | 76 | Write a function solution that,given an integer N, returns the maximum possible value 77 | obtainable by deleting one '5' digit from the decimal representation of N. It is 78 | guranteed that N will contain at least one '5' digit . 79 | 80 | Example : 81 | 1) Given N=15958, the function should return 1958 82 | 83 | 2) Given N = -5859, the function should return -589 84 | 85 | 3) Given N=-5000, the function should return 0. After deleting the '5', 86 | the only digits in the number are zeros, so its value is 0. 87 | 88 | Assume that : 89 | 90 | . N is an integer within the range 91 | [-999,995..999,995]; 92 | N contains at least one '5' digit in its decimal representation; 93 | N consists of at least two digits in its decimal representation. 94 | 95 | 96 | -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-01/P2.java: -------------------------------------------------------------------------------- 1 | /* 2 | There are N persons in a Instagram Page, the persons are identified by a 3 | unique identification number from 0 to N-1. There may exist a strange person 4 | in the IG page. 5 | 6 | The rules to identify the strange person X are: 7 | - Everyone in the IG Page follows the person X. 8 | - X does not follow anybody in that IG Page. 9 | 10 | You are given a N*N matrix IG[][] representing the followers in the IG Page, 11 | the matrix contains only 0's and 1's. 0 indicates "not follows", 12 | 1 indicates "follows". Your task is to find the strange person X among 13 | the N people. You are allowed to perform only one operation: 14 | - You can check whether M follows N, if yes, means M follows N. 15 | But it won't guarantee that N follows M. 16 | 17 | You can perform this operation as less as possible to find the strange person X. 18 | 19 | If you found a strange person X, print the identification number of X, 20 | Otherwise, print '-1' 21 | 22 | Input Format: 23 | ------------- 24 | Line-1 : An integer N, number of persons 25 | Next N lines : N space separated integers. 26 | 27 | Output Format: 28 | -------------- 29 | Print an integer, the UIN or '-1' 30 | 31 | 32 | Sample Input-1: 33 | --------------- 34 | 4 35 | 1 1 0 1 36 | 0 1 1 1 37 | 1 0 1 1 38 | 0 0 0 1 39 | 40 | Sample Output-1: 41 | ---------------- 42 | 3 43 | 44 | Explanation: 45 | ------------ 46 | Look at the hint. 47 | 48 | 49 | Sample Input-2: 50 | --------------- 51 | 4 52 | 1 1 0 1 53 | 0 1 1 1 54 | 1 0 1 1 55 | 1 0 0 1 56 | 57 | Sample Output-2: 58 | ---------------- 59 | -1 60 | */ 61 | 62 | import java.util.*; 63 | public class P2{ 64 | private static int getStrangePerson(int[][] grid,int n){ 65 | 66 | // Better caluclate the indegree and outdegree of all nodes 67 | int[] indegree = new int[n]; 68 | int[] outdegree = new int[n]; 69 | // just check the cols where there all ones 70 | for(int i = 0 ; i < n ; i++){ 71 | for(int j = 0 ; j < n ; j++){ 72 | if(grid[i][j] == 1) { 73 | indegree[j]++; 74 | outdegree[i]++; 75 | } 76 | 77 | } 78 | 79 | } 80 | 81 | // System.out.println("Indegree : " + Arrays.toString(indegree)); 82 | // System.out.println("Outdegree : " + Arrays.toString(outdegree)); 83 | 84 | for(int i = 0 ; i < n ; i++){ 85 | if(indegree[i] == n && outdegree[i] == 1) return i; 86 | } 87 | 88 | return -1; 89 | } 90 | public static void main(String[] args) { 91 | Scanner sc = new Scanner(System.in); 92 | int n = sc.nextInt(); 93 | int[][] grid = new int[n][n]; 94 | 95 | for(int i = 0 ; i < n ; i++){ 96 | for(int j = 0 ; j < n ; j++){ 97 | grid[i][j] = sc.nextInt(); 98 | } 99 | } 100 | 101 | System.out.println(getStrangePerson(grid,n)); 102 | 103 | sc.close(); 104 | } 105 | } -------------------------------------------------------------------------------- /Darwin Box/Round1_OA_Questions/Merge_Intervals.java: -------------------------------------------------------------------------------- 1 | /* 2 | You are working as a scheduling coordinator at a conference center. 3 | Your task is to optimize room usage by merging overlapping time slots 4 | to avoid booking conflicts. 5 | 6 | Input Format: 7 | ------------- 8 | First line contains n, the number of booking intervals. 9 | Next n lines each contain two space‐separated integers start_time and end_time. 10 | (Times are represented in 24-hour format (e.g., 1300 for 1:00 PM).) 11 | 12 | Output Format: 13 | -------------- 14 | The merged list of non‐overlapping intervals in sorted order. 15 | Each interval printed in HHMM HHMM format, zero‐padded to 4 digits. 16 | 17 | Constraints: 18 | ------------ 19 | -> 0000 ≤ start_time < end_time ≤ 2400 20 | -> start_time and end_time follow valid 24-hour format 21 | -> 1 ≤ n ≤ 10^5 22 | 23 | Sample Input: 24 | ------------- 25 | 4 26 | 0900 1030 27 | 1000 1200 28 | 1230 1315 29 | 1300 1445 30 | 31 | Sample Output: 32 | -------------- 33 | 0900 1200 34 | 1230 1445 35 | */ 36 | import java.util.ArrayList; 37 | import java.util.Arrays; 38 | import java.util.Collections; 39 | import java.util.List; 40 | import java.util.Scanner; 41 | 42 | public class Merge_Intervals{ 43 | private List> getMergedIntervals(List lst,final int n){ 44 | // sort according to start time 45 | Collections.sort(lst,(a,b) ->{ 46 | return a[0].compareTo(b[0]); 47 | }); 48 | 49 | String prevStartTime = lst.get(0)[0]; 50 | String prevEndTime = lst.get(0)[1]; 51 | 52 | List> ans = new ArrayList<>(); 53 | for(int i = 1 ; i < n ; i++){ 54 | String currStartTime = lst.get(i)[0]; 55 | String currEndTime = lst.get(i)[1]; 56 | 57 | if(currStartTime.compareTo(prevEndTime) <= 0){ 58 | // if currstart < prevEnd yes this can be merged into a single interval 59 | // take max of prevEnd time 60 | if(currEndTime.compareTo(prevEndTime) > 0){ 61 | // if curr > prev , update prevEndTime 62 | prevEndTime = currEndTime; 63 | } 64 | }else{ 65 | ans.add(Arrays.asList(prevStartTime,prevEndTime)); 66 | prevStartTime = currStartTime; 67 | prevEndTime = currEndTime; 68 | } 69 | } 70 | 71 | ans.add(Arrays.asList(prevStartTime,prevEndTime)); 72 | return ans; 73 | } 74 | public static void main(String... args){ 75 | int n; 76 | List lst = new ArrayList<>(); 77 | 78 | try(Scanner sc = new Scanner(System.in)){ 79 | n = sc.nextInt(); 80 | for(int i = 0 ; i < n ; i++){ 81 | lst.add(new String[]{sc.next(),sc.next()}); 82 | } 83 | } 84 | 85 | List> ans = new Merge_Intervals().getMergedIntervals(lst,n); 86 | 87 | ans.forEach(interval -> { 88 | System.out.println(interval.get(0) + " " + interval.get(1)); 89 | }); 90 | } 91 | } -------------------------------------------------------------------------------- /OffCampus/TVSEpic/Coding/MaxFromReversedDigits.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | You are given a array of integers, you need to reverse the individual element of the array, 4 | then for each element , rearrange the digits of the elements to form the maximum element and then replace all unique odd digit with # , 5 | even with * and zero with $ , Print the result of formed symbols in form of final String/ 6 | 7 | Note:- The order of characters in the final string is determined by the sequence of unique digits from each element in the array , procesed 8 | in order from the first to the last 9 | 10 | 🔍 Example 11 | 12 | Input: 13 | 14 | 3 15 | 1201 21 10 16 | 17 | Explanation: 18 | 19 | 1201 → Reverse = 1021 → Max from digits = 2110 20 | 21 | 21 → Reverse = 12 → Max from digits = 21 22 | 23 | 10 → Reverse = 1 → Max from digits = 1 24 | 25 | Now unique digits order is 2,1,0 -> resultant string is *#$ 26 | 27 | Output: 28 | *#$ 29 | 30 | Constraints 31 | 32 | 1 <= arr.length <= 10^5 33 | 34 | 0 <= arr[i] <= 10^5 35 | */ 36 | import java.util.*; 37 | 38 | public class MaxFromReversedDigits { 39 | 40 | // Main method to process the array 41 | public static String transformAndSort(String[] nums, final int n) { 42 | for (int i = 0; i < n; i++) { 43 | String num = nums[i]; 44 | 45 | // Step 1: Reverse the number and convert to char array 46 | char[] digits = new StringBuilder(num).reverse().toString().toCharArray(); 47 | 48 | // Step 2: Remove leading zeros 49 | int j = 0; 50 | while(j < digits.length && digits[j] == '0'){ 51 | j++; 52 | } 53 | 54 | // Step3:- Now sort the array from j to end 55 | Arrays.sort(digits,j,digits.length); 56 | 57 | // Step 4:- Extract the chars from j , end and reverse it and store it 58 | StringBuilder tmp = new StringBuilder(); 59 | 60 | for( ; j < digits.length ; j++){ 61 | tmp.append(digits[j]); 62 | } 63 | 64 | nums[i] = tmp.reverse().toString(); 65 | } 66 | 67 | 68 | LinkedHashSet st = new LinkedHashSet<>(); 69 | 70 | for(String num : nums){ 71 | for(char ch : num.toCharArray()){ 72 | st.add(ch); 73 | } 74 | } 75 | 76 | StringBuilder res = new StringBuilder(); 77 | 78 | for(char ch : st){ 79 | res.append(ch == '0' ? '$' : (ch - '0') % 2 == 0 ? '*' : '#'); 80 | } 81 | 82 | 83 | return res.toString(); 84 | } 85 | 86 | // Driver code for testing 87 | public static void main(String[] args) { 88 | 89 | int n; 90 | String[] nums; 91 | try (Scanner sc = new Scanner(System.in)) { 92 | n = sc.nextInt(); 93 | nums = new String[n]; 94 | 95 | for (int i = 0; i < n; i++) { 96 | nums[i] = sc.next(); 97 | } 98 | } 99 | 100 | System.out.println(transformAndSort(nums, n)); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-01/Quiz1Concepts.md: -------------------------------------------------------------------------------- 1 | # Java Code Snippet Explanations 2 | This document explains various Java code snippets and the core concepts they demonstrate. 3 | 4 | ## 🔁 Post-increment vs Pre-increment and Compound Assignment 5 | ```java 6 | int x = 5; 7 | x += x++ + ++x; 8 | System.out.print(x); // 17 9 | ``` 10 | **Explanation:** Post-increment uses the value before incrementing; pre-increment increments first. The compound assignment uses the original `x` (5), so the result is 5 + 5 + 7 = 17. 11 | 12 | ## 🧮 Operator Precedence and Post/Pre Increment 13 | ```java 14 | int a = 5; 15 | int b = 10; 16 | System.out.println(a++ * --b); // 45 17 | ``` 18 | **Explanation:** `a++` uses 5, then a becomes 6. `--b` becomes 9, so result is 5 * 9 = 45. 19 | 20 | ## 📐 Evaluation Order and Side Effects 21 | ```java 22 | int x = 5; 23 | int y = ++x + x++ + --x; 24 | System.out.println(y); // 18 25 | ``` 26 | **Explanation:** `++x` is 6, `x++` is 6 (then x becomes 7), `--x` is 6. So 6 + 6 + 6 = 18. 27 | 28 | ## 📌 String Interning and `==` vs `.equals()` 29 | ```java 30 | String s1 = "OCA"; 31 | String s2 = "O" + "C" + "A"; 32 | System.out.println(s1 == s2); 33 | ``` 34 | **Explanation:** String literals and compile-time constants are interned by Java, so both references point to the same object. Result: true. 35 | 36 | ## 🔢 String Concatenation with Mixed Types 37 | ```java 38 | System.out.println(10 + 20 + "Java" + 10 + 20); 39 | ``` 40 | **Explanation:** First 10 + 20 = 30, then string concatenation takes over: "30Java10" + 20 → "30Java1020". 41 | 42 | ## 🧠 Expression Mixing with String and Arithmetic 43 | ```java 44 | System.out.println(10 + "Java" + 5*2); 45 | System.out.println(10 + "Java" + 5/2); 46 | ``` 47 | **Explanation:** String concatenation happens left to right. `5*2 = 10`, `5/2 = 2`, so output: `10Java10` and `10Java2`. 48 | 49 | ## 💾 Integer Caching (Wrapper Class Behavior) 50 | ```java 51 | Integer a = 10; 52 | Integer b = 10; 53 | Integer c = 200; 54 | Integer d = 200; 55 | System.out.println(a == b); // true 56 | System.out.println(c == d); // false 57 | ``` 58 | **Explanation:** `Integer` values between -128 and 127 are cached, so `a == b` is true. `c == d` is false because 200 is outside cache range. 59 | 60 | ## 🔍 Reference vs Value Comparison in Wrappers 61 | ```java 62 | Integer a = 10; 63 | Integer b = new Integer(10); 64 | System.out.println(a == b); // false since references are compared 65 | System.out.println(a.equals(b)); // this is true since only values are compared 66 | ``` 67 | **Explanation:** `a == b` is false because they're different objects. `.equals()` compares values, so it's true. 68 | 69 | ## 🔁 Nested Ternary Operator 70 | ```java 71 | int x = 10; 72 | int y = 5; 73 | System.out.println(x > y ? "Greater" : x == y ? "Equal" : "Smaller"); 74 | ``` 75 | **Explanation:** `x > y` is true, so it returns "Greater". Remaining ternary parts are skipped. 76 | 77 | ## 🚫 Short-Circuit Logical Operators 78 | ```java 79 | int x = 5; 80 | System.out.println(x > 2 || x++ < 1 / 0); // No exception(output is true) 81 | System.out.println(x > 2 && x++ < 1 / 0); // ArithmeticException 82 | ``` 83 | **Explanation:** `||` short-circuits if first condition is true, so no division by zero. `&&` evaluates both if first is true, leading to exception. 84 | -------------------------------------------------------------------------------- /Verisk/Round 1/Aptitude/verbal.md: -------------------------------------------------------------------------------- 1 | ## Verbal Ability 2 | 3 | #### 1. Convert the sentence into active voice: 4 | **"It is time for the station to be closed."** 5 | 6 | Answer: 7 | "It is time for someone to close the station." 8 | 9 | >The original sentence is in passive voice.
To make it active, we add a generic subject like "someone", as the doer is not specified. 10 | 11 | ##### Questions 2,3,4 are passage based questions 12 | 13 | #### 5. Replace the sentence in quotes: 14 | **"He found the pencil 'as he cleans' the bed."** 15 | 16 | Answer: 17 | **"He found the pencil as he was cleaning the bed."** 18 | 19 | >The verb tense "cleans" (simple present) is incorrect in this context.
Since the action happened in the past, we replace it with "was cleaning" (past continuous) to maintain tense consistency. 20 | 21 | #### 6. Combine the phrases into a coherent sentence: 22 | 23 | 1. I will get money 24 | 2. my astrologer 25 | 3. towards the end of my life 26 | 27 | Answer: 28 | **"My astrologer told me that I will get money towards the end of my life."** 29 | 30 | #### 7. Fill in the blank with the correct option: 31 | **The best course of action will be _____ the message.** 32 | 33 | *Options*: 34 | a) telling 35 | b) to tell 36 | c) tell 37 | d) tell to 38 | 39 | Answer: 40 | **b) to tell** 41 | 42 | *Complete Sentence*: 43 | **"The best course of action will be to tell the message."** 44 | 45 | *Explanation*: 46 | >After phrases like "the best course of action is/will be", the correct grammatical form is the infinitive (to + verb).
Hence, "to tell" is the correct choice. 47 | 48 | #### 8. Convert the sentence into indirect speech: 49 | **The coach said, "If you stay after school tomorrow I will solve it."** 50 | 51 | Answer: 52 | **The coach said that if I stayed after school the next day, he would solve it.** 53 | 54 | Explanation: 55 | 56 | >"stay" → "stayed" (past tense) 57 | "tomorrow" → "the next day" 58 | "I will" → "he would" (will → would in indirect speech) 59 | Pronouns are changed appropriately based on context. 60 | 61 | #### 9. Fill in the blank with the correct option: 62 | **The movie had ended ____ we could arrive.** 63 | 64 | Options: 65 | a) in 66 | b) before 67 | c) by 68 | d) when 69 | 70 | Answer: 71 | **b) before** 72 | 73 | Complete Sentence: 74 | "The movie had ended before we could arrive." 75 | 76 | Explanation: 77 | >The word "before" correctly shows that the action of the movie ending happened earlier than the arrival.
Other options don't fit the temporal relationship properly in this context. 78 | 79 | #### 10. Arrange the sentences into a coherent passage: 80 | 81 | 1. It wasn't quite yet time to panic 82 | 83 | 2. At least that is what she was telling herself 84 | 85 | 3. There was still time to salvage the situation 86 | 87 | 4. The reality was that it was time to panic and there wasn't time to salvage the situation 88 | 89 | Answer: 90 | 91 | **"It wasn't quite yet time to panic. At least that is what she was telling herself. There was still time to salvage the situation. The reality was that it was time to panic and there wasn't time to salvage the situation."** 92 | 93 | Explanation: 94 | >This arrangement begins with the character’s belief, follows with her internal reassurance, builds hope, and then delivers the contrasting reality—creating a logical and dramatic flow. 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📁 KMIT Company-wise Interview Questions (2025–26) 2 | 3 | Welcome to the un-official repository for collecting **company-wise interview questions** for the KMIT 2026 batch! 4 | 5 | This initiative is meant to help all of us share and access **real interview experiences**, understand the **type of questions companies ask**, and prepare more effectively for placements. 🎯 6 | 7 | --- 8 | 9 | ## 📌 Why This Repo? 10 | 11 | - ✅ Centralized source for company-specific interview questions 12 | - ✅ Easy access to **round-wise** experience from our batchmates 13 | - ✅ Helps juniors in future batches as well 14 | - ✅ Encourages collaborative learning and preparation 15 | 16 | > 🙌 _Together we prepare smarter, faster, and better._ 17 | 18 | --- 19 | 20 | ## 🚀 How to Contribute (Step-by-Step) 21 | 22 | > 💡 Even small contributions are valuable — don't hesitate to add your experience! 23 | 24 | ### 🛠️ Step 1: Fork the Repository 25 | 26 | Click on the **Fork** button (top-right of the page) to create your own copy. 27 | 28 | ### 🖥️ Step 2: Clone Your Fork 29 | 30 | ```bash 31 | git clone https://github.com/Viishhnur/kmit-companywise-questions-25-26.git 32 | cd kmit-companywise-questions-25-26 33 | ``` 34 | 35 | ### 🔄 Step 3: Pull Latest Changes (Only for previous contributors (If you are not one of them ignore this step)) 36 | 37 | Before making any changes: 38 | 39 | ```bash 40 | git remote add upstream https://github.com/Viishhnur/kmit-companywise-questions-25-26.git 41 | git pull upstream main 42 | ``` 43 | 44 | ### 📁 Step 4: Create Company Folder 45 | 46 | If not already present, create a folder with the **company name** (e.g., `Experian`, `Epam`, `Amazon`, etc.) 47 | 48 | Inside that, create subfolders for each interview round: 49 | 50 | ``` 51 | Amazon/ 52 | ├── Round 1 - MCQs/ 53 | ├── Round 2 - Technical/ 54 | └── Round 3 - HR/ 55 | ``` 56 | 57 | Inside each file, include: 58 | 59 | - ✅ Date of interview 60 | - ✅ Mode (Online/Offline) 61 | - ✅ Questions asked (If DSA, mention LeetCode number if possible) 62 | - ✅ Topics covered 63 | - ✅ Your experience and tips 64 | 65 | > 📦 You can also contribute general resources like `resume_tips.md`, `interview_prep.md` under a `Resources/` folder. 66 | 67 | ### ✅ Step 5: Stage, Commit, and Push Your Changes 68 | 69 | ```bash 70 | git add . 71 | git commit -m "Add Amazon Round 2 coding and HR questions" 72 | git push origin main 73 | ``` 74 | 75 | 📌 **Write clear and meaningful commit messages** 76 | Avoid generic messages like `Update file` or `Fix bug`. 77 | 78 | ### 🔁 Step 6: Create a Pull Request 79 | 80 | Go to your fork on GitHub and click **"Compare & Pull Request"**, then submit it. 81 | 82 | --- 83 | 84 | ## 📝 Example Contribution Structure 85 | 86 | ``` 87 | Salesforce/ 88 | ├── Round 1 - Aptitude/ 89 | │ └── questions.md 90 | ├── Round 2 - Technical/ 91 | │ └── coding_questions.md 92 | └── Round 3 - HR/ 93 | └── hr_questions.md 94 | 95 | Amazon/ 96 | ├── Round 1 - MCQ/ 97 | ├── Round 2 - Technical/ 98 | └── Round 3 - HR/ 99 | ``` 100 | 101 | --- 102 | 103 | ## ⭐ Spread the Word 104 | 105 | If this repository helps you: 106 | 107 | - Leave a ⭐ on GitHub 108 | - Share with your friends 109 | - Contribute back when you can 110 | 111 | Together we build, learn, and succeed! 🚀 112 | 113 | --- 114 | 115 | > 💡 _"Knowledge shared is knowledge multiplied. Let’s make it count!"_ 116 | -------------------------------------------------------------------------------- /EventBrite/Last Year Questions/EventBrite_PreviousYear_Questions.txt: -------------------------------------------------------------------------------- 1 | 2 | 1. Movie Ratings 3 | Alexa loves movies and maintains a list of negative and/or positive integer ratings for the movies in her collection. She's getting ready for a film festival and wants to choose some subsequence of movies from her collection to bring such that the following conditions are satisfied: 4 | 5 | The collective sum of their ratings is maximal. 6 | 7 | She must go through her list in order and cannot skip more than one movie in a row. 8 | 9 | In other words, she cannot skip over two or more consecutive movies. For example, if 10 | ratings = [1, -3, -2], she must include either the second number or the first and third numbers to get a maximal rating sum of -3. 11 | 12 | Example 13 | If ratings = [-3, 2, 4, -1, -2, -5], 14 | Her maximal choices are [2, 4, -2] for a sum of 4. 15 | 16 | Function Description 17 | Complete the function maximizeRatings in the editor below. The function must return an integer denoting the maximum possible rating sum for Alexa's chosen subsequence of movies without reordering them. 18 | 19 | maximizeRatings has the following parameter(s): 20 | ratings(ratings[0],....ratings[n-1]): an array of integers 21 | 22 | Constraints: 23 | 1 ≤ n ≤ 10⁵ 24 | -1000 ≤ ratings[i] ≤ 1000, where 0 ≤ i < n 25 | 26 | Input 27 | ratings: a list of integers of size n (1 ≤ n ≤ 10⁵) 28 | Each ratings[i] (where 0 ≤ i < n) is in the range -1000 to 1000 29 | 30 | Sample Case 0 31 | Input 32 | 5 33 | 9 34 | -1 35 | -3 36 | 4 37 | 5 38 | 39 | Output 40 | 17 41 | 42 | Explanation 43 | Alexa picks the bolded items in ratings = [9, -1, -3, 4, 5] to get maximum rating: 44 | 9 + 4 + 5 = 17. 45 | Thus, the answer is 17. 46 | ************************************************************************************************** 47 | 48 | 2. Cached Requests 49 | There are n services numbered from 1 to n in a system, and there are m requests to be processed. The service in which the iᵗʰ request is cached is denoted by cache[i], for all 1 ≤ i ≤ m. For any request, If the request is processed from its cached service, it takes 1 unit of time. Otherwise, it takes 2 units of time. 50 | 51 | Different services can process different requests simultaneously, but one service can only process one request at a time. Find the minimum time to process all the requests by allocating each request to a service. 52 | 53 | Example 54 | It is given that n = 3, m = 5, and cache = [1, 1, 3, 1, 1]. 55 | If the 1st, 2nd, and 4th requests are assigned to the 1st service, it will take 1 unit of time each, or 3 units of time to process them in total. 56 | Assign the 3rd request to the 2nd service and the 5th request to the 3rd service. It takes 1 and 2 units of time to complete them, respectively. Therefore, all requests are processed in 3 units of time. 57 | 58 | Function Description 59 | Complete the function getMinTime in the editor below. 60 | 61 | getMinTime has the following parameters: 62 | int n: the number of services in the system 63 | int cache[m]: the service in which the request is cached (of length m) 64 | 65 | Returns 66 | int: the minimum time required to process all requests 67 | 68 | Constraints 69 | 1 ≤ n, m ≤ 2 * 10⁵ 70 | 1 ≤ cache[i] ≤ n 71 | 72 | Sample Case 0 73 | Input 74 | n = 4 75 | cache = [1, 2, 3, 4] 76 | Output 77 | 1 78 | 79 | Explanation 80 | Each request is cached in a different service. Process all of them at once, which takes 1 unit of time. -------------------------------------------------------------------------------- /Caspex/Coding/Old Questions/P1.java: -------------------------------------------------------------------------------- 1 | /* 2 | You are given an array A of size n containing positive integers, along with another array X of size m that specifies 3 | the indices of elements to be dropped from array A. 4 | 5 | Your task is to remove the elements at the specified indices from array A and then print the modified array as output. 6 | 7 | Constraints: 8 | ------------ 9 | 1 ≤ n ≤ 10^4 10 | 11 | 1 ≤ m ≤ 10^4 12 | 13 | 1 ≤ A[i] ≤ 10^6 14 | 15 | All the elements of the second array of size M should be distinct. 16 | 17 | The index of the elements in the array start from 0 18 | 19 | Any elements of array X cannot be negitive. 20 | 21 | 22 | Input Format: 23 | -------------- 24 | The first line of the input accepts an integer displaying the size of the array(n) 25 | The second line of the input accepts the elements of the array of size n. each separated by a space 26 | The third line of the input accepts an integer displaying the size of the array(m). 27 | The fourth line of input accepts the elements of the array of size m. each separated by a space. These elements contains consists of the indices we want to drop from the main array which is of size n. 28 | 29 | Output Format: 30 | -------------- 31 | A single line of output displays the array after dropping the elements. 32 | 33 | Sample Input 1: 34 | --------------- 35 | 4 36 | 1 2 3 4 37 | 2 38 | 2 3 39 | 40 | Sample Output 1: 41 | ---------------- 42 | 1 2 43 | 44 | Explanation 45 | ------------ 46 | The First line of input creates an array of size 4. The elements of this array is mentioned in the second line of input 47 | i.e.[1,2,3,4]. The third line of input is an array of size 2 which means that 2 elements from the array A need to be 48 | dropped . The fourth line of input contains the array( [2,3]) which displays that the elements of indices 2 and 3 need 49 | to be dropped from the main array([1,2,3,4]). 50 | The final output is array:[1,2] 51 | 52 | Sample Input 2: 53 | --------------- 54 | 6 55 | 3 4 5 6 3 2 56 | 1 57 | 2 58 | 59 | Sample Output 2: 60 | ---------------- 61 | 3 4 6 3 2 62 | 63 | Explanation 64 | ----------- 65 | The First line of input creates an array of size 6. The elements of this array is mentioned in the second line of input 66 | i.e.[3,4,5,6,3,2]. The third line of input is an array of size 1 which means that 1 elements from the array needs to 67 | be 68 | dropped . The fourth line of input contains the array( [2]) which displays that the elements of indices 2 need to be 69 | dropped from the main array([3,4,5,6,3,2]). 70 | The final output is array:[3,4,6,3,2] 71 | */ 72 | import java.util.*; 73 | public class P1 { 74 | private static void printModifiedArray(int[] A,int[] B,final int m,final int n){ 75 | // sort the array B 76 | Arrays.sort(B); 77 | int ptr = 0; 78 | System.out.println("Modified Arr: "); 79 | for(int i = 0 ; i < m ; i++){ 80 | if(i != B[ptr]){ 81 | System.out.print(A[i] + " "); 82 | }else{ 83 | ptr++; 84 | } 85 | } 86 | } 87 | public static void main(String[] args) { 88 | int m,n; 89 | int[] A,B; 90 | try (Scanner sc = new Scanner(System.in)) { 91 | m = sc.nextInt(); 92 | A = new int[m]; 93 | for(int i = 0 ; i < m ; i++){ 94 | A[i] = sc.nextInt(); 95 | } 96 | 97 | n = sc.nextInt(); 98 | B = new int[n]; 99 | for(int i = 0 ; i < n ; i++){ 100 | B[i] = sc.nextInt(); 101 | } 102 | } 103 | 104 | printModifiedArray(A,B,m,n); 105 | } 106 | } -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-02/P3.java: -------------------------------------------------------------------------------- 1 | /* 2 | There are P people in a Village, some of the people are relatives, 3 | others are not. Their relationship is transitive. 4 | 5 | For example, 6 | if A is a direct relative of B, and B is a direct relative of C, 7 | then A is an indirect relative of C. And we define a Relation Chain as 8 | a group of people who are direct or indirect relatives. 9 | 10 | Given a P*P matrix R represents the relationship between people 11 | in the village. If R[i][j] = 1, then the i and j persons are direct 12 | relatives with each other, otherwise not. 13 | 14 | Your task is to find out the total number of Relation Chains 15 | among all the people. 16 | 17 | Input Format: 18 | ------------- 19 | Line-1 : An integer P, number of people 20 | Next P lines : P space separated integers. 21 | 22 | Output Format: 23 | -------------- 24 | Print an integer, the total number of Relation Chains 25 | 26 | 27 | Sample Input-1: 28 | --------------- 29 | 3 30 | 1 1 0 31 | 1 1 0 32 | 0 0 1 33 | 34 | Sample Output-1: 35 | ---------------- 36 | 2 37 | 38 | Explanation: 39 | ------------ 40 | The 0-th and 1-st people are direct relatives, so they are in a relation chain. 41 | The 2-nd person himself is in a relation chain. So return 2. 42 | 43 | 44 | Sample Input-2: 45 | --------------- 46 | 3 47 | 1 1 0 48 | 1 1 1 49 | 0 1 1 50 | 51 | Sample Output-2: 52 | ---------------- 53 | 1 54 | 55 | Explanation: 56 | ------------ 57 | The 0-th and 1-st people are direct relatives, 1-st and 2-nd people 58 | are direct relatives. So, the 0-th and 2-nd people are indirect relatives. 59 | All of them in the same relative chain. So return 1. 60 | */ 61 | import java.util.*; 62 | 63 | public class P3 { 64 | // T.C:- O(N^2), S.C:- O(N) 65 | private static List> adjLst; // make this a instance variable 66 | 67 | private static void dfs(int node, int[][] grid, boolean[] visited, int n) { 68 | visited[node] = true; 69 | 70 | for (int nbr : adjLst.get(node)) { 71 | if (!visited[nbr]) { 72 | dfs(nbr, grid, visited, n); 73 | } 74 | } 75 | 76 | } 77 | 78 | private static void buildAdjList(int[][] grid, int n) { 79 | for (int i = 0; i < n; i++) { 80 | adjLst.add(new ArrayList<>()); // first create space for each list 81 | } 82 | for (int i = 0; i < n; i++) { 83 | for (int j = 0; j < n; j++) { 84 | if (grid[i][j] == 1) { 85 | adjLst.get(i).add(j); 86 | } 87 | } 88 | } 89 | 90 | } 91 | 92 | private static int findCircleNum(int[][] grid,int n) { 93 | // a simple dfs would help us 94 | boolean[] visited = new boolean[n]; 95 | 96 | adjLst = new ArrayList<>(); 97 | buildAdjList(grid, n); 98 | 99 | int cnt = 0; 100 | for (int i = 0; i < n; i++) { 101 | if (!visited[i]) { 102 | dfs(i, grid, visited, n); 103 | cnt++; 104 | } 105 | 106 | } 107 | 108 | return cnt; 109 | 110 | } 111 | 112 | public static void main(String[] args) { 113 | try(Scanner sc = new Scanner(System.in)){ 114 | 115 | int p = sc.nextInt(); 116 | int[][] persons = new int[p][p]; 117 | for(int i = 0 ; i < p ; i++){ 118 | for(int j = 0 ; j < p ; j++){ 119 | persons[i][j] = sc.nextInt(); 120 | } 121 | } 122 | 123 | System.out.println(findCircleNum(persons,p)); 124 | sc.close(); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /Caspex/Coding/Old Questions/Character_Retain.java: -------------------------------------------------------------------------------- 1 | /* 2 | A University named "XYZ" sends the question papers for the different subjects to different colleges in a zipped file 3 | along with a secret key to access them. 4 | 5 | The Dean appoints squad to different colleges and gives them the following cipher algorithm to be used to find out the 6 | password required to open the zip file: 7 | 8 | i)Take the question paper’s name P and the secret key K (which can be positive or negative). 9 | ii)Displace all the lowercase English alphabets present in P by K.All the uppercase alphabets, numbers, spaces, and 10 | special characters are retained as it is. 11 | iii)If K is positive, displace to the right and if K is negative, displace to the left. 12 | iV)The lower limit and upper limit of the character's ASCII value generated after K displacement is 65 and 126. 13 | V)During right displacement, if the value exceeds 126,then start again from 65. while during left displacement, if the 14 | value goes back from 126. 15 | 16 | The squads perform these steps to find out the password required to open the file and take out the printouts to conduct 17 | the examination. 18 | 19 | write a program by reading the input from STDIN and the output from STDOUT you should not write arbitary strings while 20 | reading the input and while printing as these contribute to the standard output. 21 | 22 | Constraints: 23 | ------------- 24 | i)P should not contain more than 50 characters. 25 | iI)-50 ≤ K ≤ 50 26 | 27 | Input Format: 28 | ------------- 29 | The first line contains the question paper's name P. 30 | The second line contains the secret key K. 31 | 32 | Output Format: 33 | -------------- 34 | The output contains a single string which is the password required to open the zip file. 35 | 36 | Sample Input 1: 37 | --------------- 38 | Operating Systems 39 | -40 40 | 41 | Sample Output 1: 42 | ---------------- 43 | OH(JwLAF) SQKL(EK 44 | 45 | Explanation-1: 46 | -------------- 47 | Given question paper name P is "Operating Systems" and k Value is -40 48 | 49 | 50 | consider the the table given below: 51 | 52 | | Character | ASCII (Before) | ASCII (After) | Result Character | Remarks | 53 | | --------- | --------------- | --------------|------------------|------------------------------------------| 54 | | O | No displacement | - | O | Uppercase alphabet, retained as it is | 55 | | p | 112 | 72 | H | | 56 | | e | 101 | 61 | { | It is below 65, so going back from 126 | 57 | | r | 114 | 74 | J | | 58 | | a | 97 | 57 | W | It is below 65, so going back from 126 | 59 | | t | 116 | 76 | L | | 60 | | i | 105 | 65 | A | | 61 | | n | 110 | 70 | F | | 62 | | g | 103 | 63 | } | It is below 65, so going back from 126 | 63 | | | No displacement | - | | White space | 64 | | S | No displacement | - | S | Uppercase alphabet, retained as it is | 65 | | y | 121 | 81 | Q | | 66 | | s | 115 | 75 | K | | 67 | | t | 116 | 76 | L | | 68 | | e | 101 | 61 | { | | 69 | | m | 109 | 69 | E | | 70 | | s | 115 | 75 | K | | 71 | 72 | 73 | 74 | Sample Input 2: 75 | -------------- 76 | X@DF* 77 | 20 78 | 79 | Sample Output 2: 80 | --------------- 81 | X@DF* 82 | 83 | 84 | Explanation 2: 85 | -------------- 86 | 87 | From the same input2, the given question paper name is "X@DF*" and the K value is 20. 88 | Here X is an Upper case alphabet, @ is a specila character ,D, F is upper case alphabets and * is aspecial character. 89 | so, all the characters are retained as it is. 90 | */ 91 | public class Character_Retain { 92 | 93 | } 94 | -------------------------------------------------------------------------------- /EventBrite/OA Questions/oa_questions.md: -------------------------------------------------------------------------------- 1 | 2 | # Eventbrite Online Assessment (OA) Questions - April 2025 3 | 4 | ## Question 1: Server Connection 5 | 6 | ### Problem Statement: 7 | A company has a network of servers represented as a tree (undirected graph with no cycles). Each server is a node. You are given: 8 | - `server_nodes`: Total number of servers (nodes) 9 | - `server_from[]`: List of edges (from nodes) 10 | - `server_to[]`: List of edges (to nodes) 11 | - `server_weight[]`: List of edge weights between connected servers 12 | - `signal_speed`: A signal can travel a path if the **total weight of that path is divisible by signal_speed** 13 | 14 | For each server `i`, calculate how many other servers it can communicate with (i.e., for every other server `j`, if the distance from i to j is divisible by `signal_speed`, it's valid). 15 | 16 | ### Input Example: 17 | ```text 18 | server_nodes = 4 19 | server_from = [1, 2, 3] 20 | server_to = [2, 3, 4] 21 | server_weight = [2, 2, 2] 22 | signal_speed = 2 23 | ``` 24 | 25 | ### Output: 26 | ```text 27 | [6, 6, 6, 6] 28 | ``` 29 | 30 | Each server can communicate with 2 others where the path weight is divisible by 2. => 31 | 32 | ### Similar LeetCode Problems: 33 | - [LeetCode 743 - Network Delay Time](https://leetcode.com/problems/network-delay-time/) 34 | - [LeetCode 787 - Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/) 35 | - [LeetCode 399 - Evaluate Division (DFS weighted graph)](https://leetcode.com/problems/evaluate-division/) 36 | 37 | ### Approach Guidance: 38 | You need to compute **all-pairs shortest paths** (Floyd-Warshall for dense graphs or Dijkstra from every node for sparse graphs). Then filter distances divisible by `signal_speed`. Since it’s a tree, better to precompute distances using **DFS from every node** (O(N^2)). 39 | 40 | ### Your Solution Template: 41 | ```java 42 | public static List getServerPairs(int serverNodes, List serverFrom, 43 | List serverTo, List serverWeight, 44 | int signalSpeed) { 45 | // TODO: Implement tree construction using adjacency list 46 | // TODO: For each node, run DFS to calculate distances to all others 47 | // TODO: Count pairs where distance is divisible by signalSpeed 48 | return new ArrayList<>(); 49 | } 50 | ``` 51 | 52 | --- 53 | 54 | ## Question 2: Maximum Reveal Difficulty 55 | **Type**: Greedy / Partitioning 56 | **Difficulty**: Medium 57 | **Tags**: Greedy, Combinatorics, Subset Sum, Partition 58 | 59 | ### Problem Statement: 60 | You are given `n` modules with a `difficulty[]` array. You need to divide them into 3 **non-empty** groups such that: 61 | - Each module is in exactly one group 62 | - Each group is assigned to a different server 63 | - Then choose one module from each group and find **max(|a-b| + |b-c| + |c-a|)** over all such selections 64 | 65 | Return the **maximum possible overall difficulty**. 66 | 67 | ### Input Example: 68 | ```text 69 | difficulty = [5, 6, 1, 4, 2] 70 | ``` 71 | 72 | ### Output: 73 | ```text 74 | 8 75 | ``` 76 | 77 | Explanation: Choose groups as: 78 | - Group 1: [5, 6, 4] 79 | - Group 2: [1] 80 | - Group 3: [2] 81 | Then from these, pick 6 (G1), 1 (G2), 2 (G3). Total difficulty: `|6-1| + |1-2| + |2-6| = 5+1+4 = 10` (or another valid optimal combination). 82 | 83 | ### Similar LeetCode Problems: 84 | - [LeetCode 805 - Split Array With Same Average](https://leetcode.com/problems/split-array-with-same-average/) 85 | - [LeetCode 698 - Partition to K Equal Sum Subsets](https://leetcode.com/problems/partition-to-k-equal-sum-subsets/) 86 | - [LeetCode 1388 - Pizza With 3n Slices (Greedy Partition)](https://leetcode.com/problems/pizza-with-3n-slices/) 87 | 88 | ### Approach Guidance: 89 | Brute-force all 3-group partitions (O(3^n)), but optimize using greedy heuristics. Maximize min/max elements among the 3 groups. 90 | 91 | ### Your Solution Template: 92 | ```java 93 | public static int getMaxDifficulty(List difficulty) { 94 | // TODO: Generate all valid 3-group partitions 95 | // TODO: For each partition, pick one value from each group and compute max(|a-b| + |b-c| + |c-a|) 96 | // Hint: This simplifies to 2 * (max - min) 97 | return 0; 98 | } 99 | ``` 100 | 101 | 102 | ### Advice: 103 | - For **Q1**, prelearn: `DFS from every node`, `Floyd-Warshall`, or `Tree DP` 104 | - For **Q2**, learn: `k-group partition logic`, `max pairwise diff`, or reduce to `max-min` selection 105 | 106 | These are **NOT easy to fully solve in 1 hr**, especially without pattern recognition. 107 | 108 | --- 109 | -------------------------------------------------------------------------------- /Darwin Box/Round1_OA_Questions/Minimum_Expression.java: -------------------------------------------------------------------------------- 1 | /* 2 | Matt likes cooking. But more than that, he likes to give gifts. 3 | And now he wants to give his girlfriend an unforgettable gift. 4 | But unfortunately he forgot the password to the safe where the gift is kept. 5 | 6 | But he knows how to hack the safe. 7 | To do this, you need to correctly answer questions asked by the embedded computer. 8 | The computer is very strange, and asks special questions. 9 | Sometimes it can ask about 10000 questions (really weird). 10 | Because of this, Matt wants you to write a program that will help him to crack the safe. 11 | 12 | The questions are different, but there is only one type of question. Several numbers are given and between them one of three characters: 13 | ‘+’, ‘–’, ‘*’ can be inserted. 14 | Note that in this case there is no operator‐precedence — that is, you must evaluate strictly left to right. 15 | For example: 1 – 2 * 3 must be interpreted as (1 – 2) * 3 = –3 and not as 1 – (2*3). 16 | The computer asks: What is the minimum possible value of any valid expression you can form by inserting one operator between each adjacent pair of numbers? 17 | 18 | Input Format: 19 | ------------- 20 | Line-1: an integer T denoting the number of test cases. 21 | Then for each test case: 22 | - A line containing a positive integer N 23 | - A line containing N space‐separated integers A[1], A[2], …, A[N] (these are the numbers, in order, with no operators). 24 | 25 | Output Format: 26 | -------------- 27 | For each test case, output a single line containing the minimal value of any valid expression you can form. 28 | 29 | Constraints: 30 | ------------- 31 | 1 ≤ T ≤ 10^5 32 | 1 ≤ N ≤ 10 33 | –9 ≤ A[i] ≤ 9 34 | 35 | Sample Input: 36 | ------------- 37 | 2 38 | 3 39 | 1 2 3 40 | 1 41 | 9 42 | 43 | Sample Output: 44 | -------------- 45 | -4 46 | 9 47 | 48 | Explanation 49 | Test case 1: best is 1 – 2 – 3 = –4. 50 | Test case 2: only one number, 9. 51 | */ 52 | import java.util.*; 53 | public class Minimum_Expression{ 54 | private void dfs(int i,long resTillNow,int[] nums,final int n,long[] mini){ 55 | 56 | if(i == n){ 57 | mini[0] = Math.min(resTillNow,mini[0]); // minimize the result 58 | return; 59 | } 60 | 61 | long currNum = nums[i]; 62 | 63 | if(i == 0){ 64 | dfs(i+1,currNum,nums,n,mini); 65 | }else{ 66 | dfs(i+1,resTillNow + currNum,nums,n,mini); 67 | dfs(i+1,resTillNow - currNum,nums,n,mini); 68 | dfs(i+1,resTillNow * currNum,nums,n,mini); 69 | } 70 | 71 | } 72 | 73 | private long dfs2(int i,long resTillNow,int[] nums,final int n){ 74 | if(i == n){ 75 | return resTillNow; 76 | } 77 | 78 | long currNum = nums[i]; 79 | 80 | long a = dfs2(i+1,resTillNow + currNum,nums,n); 81 | long b = dfs2(i+1,resTillNow - currNum,nums,n); 82 | long c = dfs2(i+1,resTillNow * currNum,nums,n); 83 | 84 | return Math.min(a,Math.min(b,c)); 85 | 86 | } 87 | 88 | private long dfs2Memo(int i,long resTillNow,int[] nums,final int n,Map dp){ 89 | if(i == n){ 90 | return resTillNow; 91 | } 92 | 93 | String key = i + "," + resTillNow; 94 | if(dp.containsKey(key)){ 95 | return dp.get(key); 96 | } 97 | 98 | long currNum = nums[i]; 99 | 100 | long a = dfs2Memo(i+1,resTillNow + currNum,nums,n,dp); 101 | long b = dfs2Memo(i+1,resTillNow - currNum,nums,n,dp); 102 | long c = dfs2Memo(i+1,resTillNow * currNum,nums,n,dp); 103 | 104 | long res = Math.min(a,Math.min(b,c)); 105 | dp.put(key,res); 106 | 107 | return res; 108 | 109 | } 110 | 111 | private void printMinValue(int[] nums,final int n){ 112 | 113 | // Approach-i) Recursion Way-1 114 | // long[] mini = {Long.MAX_VALUE}; 115 | // dfs(0,0L,nums,n,mini); 116 | // System.out.println(mini[0]); 117 | 118 | // Approach-ii) Another way of recursion 119 | // System.out.println(dfs2(1,nums[0],nums,n)); 120 | 121 | // Approach-iii) Memoization 122 | System.out.println(dfs2Memo(1,nums[0],nums,n,new HashMap<>())); 123 | } 124 | public static void main(String... args){ 125 | int T; 126 | 127 | Minimum_Expression obj = new Minimum_Expression(); 128 | try(Scanner sc = new Scanner(System.in)){ 129 | T = sc.nextInt(); 130 | 131 | while(T-- > 0){ 132 | int n = sc.nextInt(); 133 | int[] nums = new int[n]; 134 | 135 | for(int i = 0 ; i < n ; i++) nums[i] = sc.nextInt(); 136 | 137 | obj.printMinValue(nums,n); 138 | } 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /Verisk/Round 1/Aptitude/arithmetic.md: -------------------------------------------------------------------------------- 1 | ### Arithmetic Aptitude 2 | 3 | #### 1. find the value of p such that 12p modulo 7 = 6. 4 | 5 | Answer: 6 | 7 | ##### Solution to the Modular Equation 12p ≡ 6 (mod 7) 8 | Let's break it down: 9 | 10 | 1. Simplify the modulus: 11 | First, we simplify 12(mod7): 12 | 12=1×7+5 13 | So, 12≡5(mod7). 14 | 15 | 2. Rewrite the congruence: 16 | Now, substitute this back into the original equation: 17 | 5p≡6(mod7) 18 | 19 | 3. Find the multiplicative inverse: 20 | To isolate p, we need to find the multiplicative inverse of 5 modulo 7. This is a number, let's call it x, such that 5x≡1(mod7). 21 | Let's test values: 22 | 23 | - 5×1=5≡5(mod7) 24 | - 5×2=10≡3(mod7) 25 | - 5×3=15≡1(mod7) 26 | - So, the multiplicative inverse of 5(mod7) is 3. 27 | 28 | 4. Multiply by the inverse: 29 | Multiply both sides of the congruence 5p≡6(mod7) by 3: 30 | 3×5p≡3×6(mod7) 31 | 15p≡18(mod7) 32 | 33 | 5. Simplify again: 34 | Now, simplify 15(mod7) and 18(mod7): 35 | - 15≡1(mod7) 36 | 37 | - 18≡4(mod7) 38 | 39 | 6. Final result: 40 | Substituting these back into the congruence: 41 | - 1p≡4(mod7) 42 | - p≡4(mod7) 43 | 44 | The smallest non-negative integer value for p is 4. 45 | 46 | #### 2. A shopkeeper purchased some tables for ₹2400. He sold two-thirds of these tables at a 10% loss. What profit percentage must he sell the remaining tables for to achieve an overall profit of 25% on the total cost? 47 | 48 | Answer: 49 | 50 | Here's how to solve the problem step-by-step: 51 | 52 | 1. Calculate the Cost of the First Batch: 53 | The shopkeeper sold 2/3 of the tables. 54 | Cost of 2/3 of tables = 32​×₹2400=₹1600. 55 | 56 | 2. Calculate the Selling Price of the First Batch: 57 | These tables were sold at a 10% loss. 58 | Loss amount = 10% of ₹1600=10010​×1600=₹160. 59 | Selling Price of the first batch = Cost - Loss = ₹1600−₹160=₹1440. 60 | 61 | 3. Calculate the Cost of the Remaining Tables: 62 | The remaining tables are 1−2/3=1/3 of the total tables. 63 | Cost of remaining 1/3 tables = 31​×₹2400=₹800. 64 | 65 | 4. Calculate the Desired Overall Selling Price: 66 | The shopkeeper wants an overall profit of 25% on the total cost (₹2400). 67 | Desired overall profit = 25% of ₹2400=10025​×2400=₹600. 68 | Desired overall Selling Price = Total Cost + Desired Profit = ₹2400+₹600=₹3000. 69 | 70 | 5. Calculate the Required Selling Price for the Remaining Tables: 71 | To achieve the desired overall selling price, the remaining tables must be sold for: 72 | Selling Price of remaining tables = Desired overall Selling Price - Selling Price of first batch 73 | Selling Price of remaining tables = ₹3000−₹1440=₹1560. 74 | 75 | 5. Calculate the Profit Percentage for the Remaining Tables: 76 | Profit on remaining tables = Selling Price of remaining tables - Cost of remaining tables 77 | Profit on remaining tables = ₹1560−₹800=₹760. 78 | 79 | Profit Percentage = (CostProfit​)×100% 80 | Profit Percentage = (₹800₹760​)×100%=0.95×100%=95%. 81 | 82 | **Therefore, the shopkeeper must sell the remaining tables at a 95% profit to achieve an overall 25% profit.** 83 | 84 | #### 3. What is the simple interest percentage for an interest of ₹72 on a principal amount of ₹400 over a period of 2 years? 85 | 86 | Answer: 87 | 88 | To find the simple interest percentage (rate), we use the simple interest formula: 89 | 90 | Simple Interest (SI)=(Principal (P)×Rate (R)×Time (T)​)/100 91 | 92 | We are given: 93 | 94 | - Simple Interest (SI) = ₹72 95 | 96 | - Principal (P) = ₹400 97 | 98 | - Time (T) = 2 years 99 | 100 | We need to find the Rate (R). 101 | 102 | **Rearranging the formula to solve for R: 103 | R= (SI×100)/ (P×T) ​** 104 | 105 | Now, substitute the given values into the formula: 106 | R = (72\*100)/400\*2 107 | **Therefore, the simple interest percentage is 9%.** 108 | 109 | #### 4. The sum of two numbers is 72. The two numbers cannot be in which of the following ratios? 110 | 111 | A) 1:1 112 | B) 3:5 113 | C) 5:7 114 | D) 7:9 115 | E) 5:13 116 | 117 | **D) 7:9** 118 | 119 | Because 72 ÷ (7+9) = 72 ÷ 16 = 4.5, which is not an integer, so the numbers can’t be in 7:9 ratio. 120 | 121 | #### 5. A train is moving at a speed of 210 km/h. How much time will it take to cover a distance of 700 meters? 122 | 123 | Answer: 124 | **Time = 12 seconds** 125 | - a kmph = a \* (5/18) m/s 126 | - t = (d/s) seconds 127 | 128 | #### 6. A number is divided into two parts in the ratio 11:13. Which of the following numbers cannot be divided in this ratio? 129 | 130 | Options: 131 | A) 72 132 | B) 144 133 | C) 112 134 | D) 240 135 | 136 | Answer: 137 | **C) 112** 138 | Explanation: 139 | 140 | - To divide a number in the ratio 11:13, the total must be divisible by: 141 | 11+13=24 142 | 11+13=24 143 | 144 | Now check each option: 145 | 146 | 72 ÷ 24 = 3 ✅ 147 | 144 ÷ 24 = 6 ✅ 148 | 112 ÷ 24 = 4.666 ❌ 149 | 240 ÷ 24 = 10 ✅ 150 | 151 | *Also Pie diagram based questions are asked in this section* -------------------------------------------------------------------------------- /EventBrite/OA Questions/ServerConnections.java: -------------------------------------------------------------------------------- 1 | /* 2 | Question 1: Server Connection 3 | 4 | A company has a network of servers represented as a tree (undirected graph with no cycles). Each server is a node. You are given: 5 | - `server_nodes`: Total number of servers (nodes) 6 | - `server_from[]`: List of edges (from nodes) 7 | - `server_to[]`: List of edges (to nodes) 8 | - `server_weight[]`: List of edge weights between connected servers 9 | - `signal_speed`: A signal can travel a path if the total weight of that path is divisible by signal_speed 10 | 11 | For each server `i`, calculate how many other servers it can communicate with 12 | (i.e., for every other server `j`, if the distance from i to j is divisible by `signal_speed`, it's valid). 13 | 14 | 15 | Sample Input-1:- 16 | 17 | server_nodes = 4 18 | edges = 3 19 | server_from = [1, 1, 2] 20 | server_to = [2, 3, 4] 21 | server_weight = [2, 5, 3] 22 | signal_speed = 5 23 | 24 | 25 | Sample Output-1:- 26 | [2, 0, 2, 2] 27 | 28 | Sample Input-2:- 29 | 30 | server_nodes = 4 31 | edges = 3 32 | server_from = [1, 2, 3] 33 | server_to = [2, 3, 4] 34 | server_weight = [2, 2, 2] 35 | signal_speed = 2 36 | 37 | 38 | Sample Output-2:- 39 | [6, 6, 6, 6] 40 | Each server can communicate with 3 others where the path weight is divisible by 2. so 3*(3-1) => 6 41 | */ 42 | import java.util.*; 43 | 44 | class Graph { 45 | private final int nodes; 46 | private final int edges_cnt; 47 | private final List> adjLst; 48 | 49 | public Graph(int n, int edges) { 50 | this.nodes = n; 51 | this.edges_cnt = edges; 52 | this.adjLst = new ArrayList<>(); 53 | } 54 | 55 | public void buildAdjList(List server_from, List server_to, List server_weight) { 56 | 57 | for (int i = 0; i <= nodes; i++) { 58 | adjLst.add(new ArrayList<>()); 59 | } 60 | 61 | for (int i = 0; i < edges_cnt; i++) { // in this edges_cnt is n - 1 since complete graph 62 | int u = server_from.get(i); 63 | int v = server_to.get(i); 64 | int wt = server_weight.get(i); 65 | 66 | adjLst.get(u).add(new int[] { v, wt }); 67 | adjLst.get(v).add(new int[] { u, wt }); 68 | 69 | } 70 | 71 | } 72 | 73 | private int bfs(int start, int signal_speed) { 74 | boolean[] visited = new boolean[nodes + 1]; 75 | Queue qu = new LinkedList<>(); 76 | 77 | // initally push {start,0} -> (node,dist from j) 78 | 79 | qu.offer(new int[] { start, 0 }); 80 | visited[start] = true; 81 | 82 | int reachableCnt = 0; 83 | 84 | while (!qu.isEmpty()) { 85 | int[] curr = qu.poll(); 86 | int curr_node = curr[0]; 87 | int dist_from_start = curr[1]; 88 | 89 | // check if this can be included in our answer 90 | if (curr_node != start && dist_from_start % signal_speed == 0) { 91 | reachableCnt++; 92 | } 93 | 94 | // go to nbrs and add them into queue if un visited 95 | for (int[] nbrs : adjLst.get(curr_node)) { 96 | int nbr = nbrs[0]; 97 | int d = nbrs[1]; 98 | 99 | if (!visited[nbr]) { 100 | visited[nbr] = true; 101 | qu.offer(new int[] { nbr, d + dist_from_start }); 102 | } 103 | } 104 | } 105 | // ordered pairs among reachableCount nodes: r * (r - 1) 106 | return reachableCnt * (reachableCnt - 1); // rC2 is number of pairs (j,k) 107 | 108 | } 109 | 110 | public List getServerPairs(int signalSpeed) { 111 | List res = new ArrayList<>(); 112 | 113 | // May be BFS helps me out , if i am able to calulclate distance of every node 114 | // from every other node 115 | for (int node = 1; node <= nodes; node++) { 116 | // start a BFS 117 | res.add(bfs(node, signalSpeed)); 118 | } 119 | 120 | return res; 121 | } 122 | 123 | } 124 | 125 | public class ServerConnections { 126 | public static void main(String[] args) { 127 | try (Scanner sc = new Scanner(System.in)) { 128 | int nodes = sc.nextInt(); 129 | int edges = sc.nextInt(); // should be nodes - 1 130 | 131 | // sc.nextLine(); 132 | List from = new ArrayList<>(); 133 | for (int i = 0; i < edges; i++) { 134 | from.add(sc.nextInt()); 135 | 136 | } 137 | 138 | List to = new ArrayList<>(); 139 | for (int i = 0; i < edges; i++) { 140 | to.add(sc.nextInt()); 141 | 142 | } 143 | 144 | List wt = new ArrayList<>(); 145 | for (int i = 0; i < edges; i++) { 146 | wt.add(sc.nextInt()); 147 | 148 | } 149 | 150 | int signal_speed = sc.nextInt(); 151 | 152 | // Now create the graph and build the adjLst 153 | Graph g = new Graph(nodes, edges); 154 | g.buildAdjList(from, to, wt); 155 | 156 | System.out.println(g.getServerPairs(signal_speed)); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /DBS/OA_24th_March_2025/mcqs.md: -------------------------------------------------------------------------------- 1 | # DBS Online Assessment (OA) - MCQs with Answers 2 | 3 | ## 1. OSI Model Standards 4 | **Question:** Allies while working on a project using a network wanted the layers in the OSI model. They are converted into which standards? 5 | - A) 2.25 6 | - B) 3.25 7 | - C) 7 8 | - D) 6 9 | **Answer:** C) 7 10 | 11 | ## 2. Subnet ID Calculation 12 | **Question:** What is the subnet ID of a host with an IP address of 172.16.66.0/21? 13 | - A) 172.16.64.0 14 | - B) 172.16.66.0 15 | - C) 172.16.68.0 16 | - D) 172.16.70.0 17 | **Answer:** A) 172.16.64.0 18 | 19 | ## 3. Transmission Delay 20 | **Question:** If the packet length is 64 bits per 1 Mbps Ethernet connection, what is the transmission delay? 21 | - A) 64 µs 22 | - B) 32 µs 23 | - C) 128 µs 24 | - D) 16 µs 25 | **Answer:** A) 64 µs 26 | 27 | ## 4. Deadlock Prevention in RDBMS 28 | **Question:** Which schema is used to prevent deadlock in RDBMS? 29 | - A) Wait-Die 30 | - B) Wound-Wait 31 | - C) Both A and B 32 | - D) None of the above 33 | **Answer:** C) Both A and B 34 | 35 | ## 5. CPU Utilization Calculation 36 | **Question:** Two processors P1 and P2 have: 37 | - P1: Period = 30 min, Burst Time = 20 min 38 | - P2: Period = 60 min, Burst Time = 29 min 39 | Find total CPU utilization. 40 | - A) 95% 41 | - B) 90% 42 | - C) 85% 43 | - D) 80% 44 | **Answer:** B) 90% 45 | 46 | ## 6. I/O Queue in OS 47 | **Question:** In Operating Systems, which list contains processes waiting for I/O on a specific device? 48 | - A) Driver I.O.Q 49 | - B) Freelist 50 | - C) Deviceless 51 | - D) None of these 52 | **Answer:** A) Driver I.O.Q 53 | 54 | ## 7. IPC Mechanisms 55 | **Question:** Which is NOT part of Inter-Process Communication (IPC)? 56 | - A) Shared Memory 57 | - B) Message Passing 58 | - C) Semaphore 59 | - D) Message Interruption 60 | **Answer:** D) Message Interruption 61 | 62 | ## 8. Multiprocessing Systems 63 | **Question:** In which system does each processor run an identical copy of the OS and communicate when required? 64 | - A) Symmetric Multiprocessing 65 | - B) Symmetric Multithreading 66 | - C) Asymmetric Multiprocessing 67 | - D) Asymmetric Multithreading 68 | **Answer:** A) Symmetric Multiprocessing 69 | 70 | ## 9. Concurrent Support in OS 71 | **Question:** Which mechanism provides concurrency support in an OS? 72 | - A) Semaphore Monitors 73 | - B) Message-Passing Monitors 74 | - C) Semaphore Message-Passing 75 | - D) Semaphore Monitor Message-Passing 76 | **Answer:** D) Semaphore Monitor Message-Passing 77 | 78 | ## 10. Network Tracing in Shell Scripting 79 | **Question:** In shell scripting, which command is used to trace existing networks? 80 | - A) trace-ip 81 | - B) trace-path 82 | - C) trace-route 83 | **Answer:** C) trace-route 84 | 85 | ## 11. Red-Black Tree Deletion 86 | **Question:** What is the deletion time complexity in a Red-Black Tree? 87 | - A) O(n) 88 | - B) O(log n) 89 | - C) O(1) 90 | - D) O(n log n) 91 | **Answer:** B) O(log n) 92 | 93 | ## 12. Binomial Heap Properties 94 | **Question:** Which of the following is TRUE about Binomial Heaps? 95 | - A) Binomial heap is a set of binomial trees. 96 | - B) Binary trees in this heap are represented as rightmost child and left siblings. 97 | - C) A binomial tree must be represented in a way that allows sequential access to siblings starting from the leftmost sibling. 98 | - D) All of the above 99 | **Answer:** D) All of the above 100 | 101 | ## 13. Sorting Algorithm Complexity 102 | **Question:** What is the time complexity of TimSort and CubeSort? 103 | - A) O(n log n) 104 | - B) O(n^2) 105 | - C) O(n) 106 | - D) O(n^3) 107 | **Answer:** A) O(n log n) 108 | 109 | ## 14. Binomial Heap Insertion Time Complexity 110 | **Question:** What is the time complexity of inserting an element in a Binomial Heap? 111 | - A) O(1) 112 | - B) O(log n) 113 | - C) O(n) 114 | - D) O(n log n) 115 | **Answer:** B) O(log n) 116 | 117 | ## 15. Red-Black Tree Deletion Time Complexity 118 | **Question:** What is the time complexity of deleting a node in a Red-Black Tree? 119 | - A) O(n) 120 | - B) O(log n) 121 | - C) O(1) 122 | - D) O(n log n) 123 | **Answer:** B) O(log n) 124 | 125 | ## 16. Sorting Algorithm Complexity Comparison 126 | **Question:** Which of the following sorting algorithms has the worst-case time complexity of O(n log n)? 127 | - A) TimSort 128 | - B) Merge Sort 129 | - C) CubeSort 130 | - D) Quick Sort (worst-case O(n²)) 131 | **Answer:** A) TimSort, B) Merge Sort, C) CubeSort 132 | 133 | ## 17. Role of Foreign Key in RDBMS 134 | **Question:** What is the primary role of a foreign key in a relational database? 135 | - A) To enforce referential integrity 136 | - B) To improve query speed 137 | - C) To act as the primary key of a table 138 | - D) To store large text data 139 | **Answer:** A) To enforce referential integrity 140 | 141 | ## 18. Disadvantage of Linked Lists 142 | **Question:** What is one major disadvantage of using a linked list compared to an array? 143 | - A) Fixed size allocation 144 | - B) Inefficient memory usage due to pointers 145 | - C) Limited traversal 146 | - D) Inability to store dynamic data 147 | **Answer:** B) Inefficient memory usage due to pointers 148 | 149 | ## 19. Insertion in a Doubly Linked List 150 | **Question:** What is the time complexity of inserting an element at beginning in a Doubly Linked List? 151 | - A) O(1) 152 | - B) O(n) 153 | - C) O(log n) 154 | - D) O(n log n) 155 | **Answer:** A) O(1) 156 | 157 | --- 158 | -------------------------------------------------------------------------------- /OffCampus/Codevita/Zone2/unogame.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Uno Game 3 | Problem Description 4 | It was a lazy Sunday, and Dhruv was feeling bored. He picked up his phone and sent a message in his group, inviting anyone interested in playing Uno to come over. Within a few minutes, N children from the neighbourhood arrived to join the fun. 5 | 6 | Among the group, there are some friends-pairs and some rivals-pairs. 7 | 8 | Friends: If one friend is selected, the other must also be selected into the game. Each friends pair always consists of exactly two members, and no person can belong to more than one friends pair. For example, if (A, B) is a friend pair, neither A nor B will appear in any other friend pair. 9 | Rivals: Both members of a rival pair cannot be selected into the team. 10 | Each player has a uno score representing their skill level. Dhruv sets a limit for the team's total uno score and tries to select the maximum number of players without exceeding that limit. 11 | 12 | Dhruv wanted to start the game quickly, but he is unsure which players to pick. Can you help him choose the optimal team? 13 | 14 | Constraints 15 | 1 <= length of player name <= 10 16 | 17 | 1 <= max limit Dhruv set <= 1000 18 | 19 | 1 <= skill level of each player <= 100 20 | 21 | 1 <= total number of players <= 25 22 | 23 | 1 <= number of friends + number of rival pairs <= 10 24 | 25 | Input 26 | The first line contains an integer N, the total number of players. 27 | 28 | The second line contains N space-separated strings, representing the player's names. 29 | 30 | The third line contains N space-separated integers, representing the skill level of each corresponding player. 31 | 32 | The fourth line contains an integer N1, the number of friend pairs. 33 | 34 | The next N1 lines each contain two space-separated names, representing a pair of friends. 35 | 36 | The following line contains an integer N2, the number of rival pairs. 37 | 38 | The next N2 lines each contain two space-separated names, representing a pair of rivals. 39 | 40 | The last line contains a single integer, representing the skill limit set by Dhruv. 41 | 42 | Output 43 | Print the maximum number of players Dhruv can select obeying the friend, rival, and the skill limit rules. 44 | 45 | Time Limit (secs) 46 | 1 47 | 48 | Examples 49 | Example 1 50 | 51 | Input 52 | 53 | 10 54 | 55 | Ram Raj Vishnu Teja Alekhya Keerti Ganesh Seetha Rakesh Latha 56 | 57 | 1 2 3 4 5 6 7 8 9 1 58 | 59 | 2 60 | 61 | Ram Latha 62 | 63 | Alekhya Keerti 64 | 65 | 3 66 | 67 | Ram Teja 68 | 69 | Raj Rakesh 70 | 71 | Seetha Raj 72 | 73 | 10 74 | 75 | Output 76 | 77 | 4 78 | 79 | Explanation 80 | 81 | Dhruv can form a team consisting of {Ram, Latha, Raj, Vishnu} that follows all the friends and rival rules. The combined skill value of this team is 1 + 1 + 3 + 4 = 9, which is within the limit of 10. Therefore, Dhruv can select a maximum of 4 players, and no other combination can include more people than this. 82 | 83 | Example 2 84 | 85 | Input 86 | 87 | 8 88 | 89 | Aarav Maya Rohan Neha Karan Sana Vikram Isha 90 | 91 | 1 4 9 10 11 17 2 6 92 | 93 | 2 94 | 95 | Aarav Isha 96 | 97 | Maya Karan 98 | 99 | 2 100 | 101 | Aarav Neha 102 | 103 | Rohan Neha 104 | 105 | 80 106 | 107 | Output 108 | 109 | 7 110 | 111 | Explanation 112 | 113 | Within the skill limit, 114 | Dhruv can select everyone except Neha. 115 | So, the maximum number of players he can select is 7, hence print the same. 116 | ''' 117 | 118 | 119 | 120 | # Input 121 | n = int(input()) 122 | names = input().split() 123 | skills_level = list(map(int, input().split())) 124 | skill_map = dict(zip(names, skills_level)) 125 | 126 | n1 = int(input()) 127 | friends = {} 128 | for _ in range(n1): 129 | a, b = input().split() 130 | friends[a] = b 131 | friends[b] = a 132 | 133 | n2 = int(input()) 134 | rivals = {name: set() for name in names} 135 | for _ in range(n2): 136 | a, b = input().split() 137 | rivals[a].add(b) 138 | rivals[b].add(a) 139 | 140 | limit = int(input()) 141 | 142 | res = 0 143 | 144 | def backtrack(i, team_list, curr_skill): 145 | global res 146 | if curr_skill > limit: 147 | return 148 | if len(team_list) + (n - i) <= res: 149 | return 150 | 151 | res = max(res, len(team_list)) 152 | 153 | if i == n: 154 | return 155 | 156 | name = names[i] 157 | 158 | backtrack(i + 1, team_list, curr_skill) 159 | 160 | valid = True 161 | 162 | if name in team_list: 163 | return 164 | 165 | if name in friends: 166 | f = friends[name] 167 | 168 | if f in team_list: 169 | pair = [name] 170 | else: 171 | pair = [name, f] 172 | else: 173 | pair = [name] 174 | 175 | # check for rival conflicts 176 | for p in pair: 177 | for r in rivals[p]: 178 | if r in team_list: 179 | valid = False 180 | break 181 | if not valid: 182 | break 183 | 184 | if valid: 185 | total_skill = curr_skill + sum(skill_map[p] for p in pair) 186 | if total_skill <= limit: 187 | for p in pair: 188 | team_list.add(p) 189 | backtrack(i + 1, team_list, total_skill) 190 | for p in pair: 191 | team_list.remove(p) 192 | 193 | backtrack(0, set(), 0) 194 | print(res) 195 | -------------------------------------------------------------------------------- /DBS/sample_interview_questions.md: -------------------------------------------------------------------------------- 1 | 2 | # Java Interview Concepts – Quick Guide 3 | 4 | This document contains compiled answers to frequently asked Java interview questions for quick revision. 5 | 6 | --- 7 | 8 | ## ✅ 1. What is a Singleton Class in Java? 9 | 10 | A **Singleton class** ensures that only **one instance** of the class is created and provides a **global point of access** to it. 11 | 12 | ### 🔑 Key Features: 13 | - Private constructor 14 | - Static instance 15 | - Public static method to get the instance 16 | 17 | ```java 18 | public class Singleton { 19 | private static Singleton instance; 20 | 21 | private Singleton() {} 22 | 23 | public static Singleton getInstance() { 24 | if (instance == null) { 25 | instance = new Singleton(); 26 | } 27 | return instance; 28 | } 29 | } 30 | ``` 31 | 32 | --- 33 | 34 | ## ✅ 2. What is an Immutable Class? 35 | 36 | An **immutable class** is one whose object **cannot be modified** after creation. 37 | 38 | ### Rules: 39 | - Make the class `final` 40 | - Make fields `private final` 41 | - No setters 42 | 43 | ```java 44 | public final class Student { 45 | private final String name; 46 | private final int roll; 47 | 48 | public Student(String name, int roll) { 49 | this.name = name; 50 | this.roll = roll; 51 | } 52 | 53 | public String getName() { return name; } 54 | public int getRoll() { return roll; } 55 | } 56 | ``` 57 | 58 | --- 59 | 60 | ## ✅ 3. Is Java 100% Object-Oriented? 61 | 62 | **No**, because Java supports **primitive types** like `int`, `char`, etc., which are **not objects**. 63 | 64 | --- 65 | 66 | ## ✅ 4. What Are Wrapper Classes? 67 | 68 | Wrapper classes are object representations of primitives: 69 | | Primitive | Wrapper | 70 | |----------|---------| 71 | | int | Integer | 72 | | boolean | Boolean | 73 | | char | Character | 74 | | ... | ... | 75 | 76 | Supports autoboxing and unboxing: 77 | ```java 78 | Integer x = 10; // autoboxing 79 | int y = x; // unboxing 80 | ``` 81 | 82 | --- 83 | 84 | ## ✅ 5. What Are SOLID Principles? 85 | 86 | | Principle | Meaning | 87 | |-----------|--------------------------------------| 88 | | S | Single Responsibility | 89 | | O | Open/Closed | 90 | | L | Liskov Substitution | 91 | | I | Interface Segregation | 92 | | D | Dependency Inversion | 93 | 94 | Used to write clean, maintainable OOP code. 95 | 96 | --- 97 | 98 | ## ✅ 6. Comparable vs Comparator 99 | 100 | | Feature | Comparable | Comparator | 101 | |-------------|--------------------|--------------------| 102 | | Method | compareTo() | compare() | 103 | | Location | In class | Outside class | 104 | | Use Case | Natural ordering | Custom ordering | 105 | 106 | --- 107 | 108 | ## ✅ 7. Advantages of Collections 109 | 110 | - Dynamic size 111 | - Predefined data structures 112 | - Thread-safe options 113 | - Rich APIs 114 | - Supports generics 115 | 116 | --- 117 | 118 | ## ✅ 8. How Does ConcurrentHashMap Work? 119 | 120 | - Thread-safe, high-performance `Map` 121 | - Java 8+: Bucket-level locking (not whole map) 122 | - Uses `volatile`, `CAS`, and fine-grained synchronization 123 | 124 | --- 125 | 126 | ## ✅ 9. What is Serialization? 127 | 128 | Converts object → byte stream for storage/networking. 129 | 130 | ### Serializable Interface 131 | - Marker interface (no methods) 132 | - Use `transient` to skip fields 133 | - Use `serialVersionUID` for versioning 134 | 135 | --- 136 | 137 | ## ✅ 10. Can a Class Implement Multiple Interfaces? 138 | 139 | **Yes!** Java allows multiple interface implementation. 140 | 141 | ```java 142 | class A implements X, Y { } 143 | ``` 144 | 145 | --- 146 | 147 | ## ✅ 11. What Is a Static Nested Class? 148 | 149 | - A nested class declared `static` 150 | - Doesn’t access outer class instance 151 | - Used for utility/helper classes 152 | 153 | ```java 154 | class Outer { 155 | static class Nested { 156 | void show() {} 157 | } 158 | } 159 | ``` 160 | 161 | --- 162 | 163 | ## ✅ 12. How to Prevent Object Creation? 164 | 165 | - Make constructor `private` 166 | - Throw exception inside constructor 167 | - Use `abstract` class 168 | - Use `enum` (for singleton) 169 | 170 | --- 171 | 172 | ## ✅ 13. Is Callable a Functional Interface? 173 | 174 | **Yes**, it has one method: `V call() throws Exception;` 175 | 176 | Can be used with lambdas. 177 | 178 | --- 179 | 180 | ## ✅ 14. What Is Synchronization? 181 | 182 | > **One-line answer**: A mechanism that ensures only **one thread can access** a block of code/object at a time. 183 | 184 | --- 185 | 186 | ## ✅ 15. What Is ExecutorService? 187 | 188 | > A Java API that manages a pool of threads for executing `Runnable` and `Callable` tasks asynchronously. 189 | 190 | ```java 191 | ExecutorService executor = Executors.newFixedThreadPool(3); 192 | executor.submit(() -> System.out.println("Hello")); 193 | executor.shutdown(); 194 | ``` 195 | 196 | --- 197 | 198 | ## ✅ 16. Difference Between Abstract Class and Interface 199 | 200 | | Feature | Abstract Class | Interface | 201 | |------------------|------------------------|-----------------------| 202 | | Methods | Abstract + concrete | Abstract (default, static) | 203 | | Variables | Any type | `public static final` | 204 | | Constructor | ✅ Yes | ❌ No | 205 | | Multiple Inheritance | ❌ No | ✅ Yes | 206 | 207 | --- 208 | 209 | ## ✅ 17. What Is the `transient` Keyword? 210 | 211 | Used to mark a variable **not to be serialized**. 212 | 213 | ```java 214 | transient String password; 215 | ``` 216 | 217 | Useful for security, sensitive data, or non-serializable fields. 218 | 219 | --- 220 | 221 | 222 | -------------------------------------------------------------------------------- /OffCampus/Codevita/Zone2/makehands.py: -------------------------------------------------------------------------------- 1 | ''' 2 | lets move onto next one: 3 | 4 | Make Hands 5 | Problem Description 6 | Vaishnavi and Suraj, two close friends, have invented a fun two-player card game using a standard 52-card deck. The gameplay revolves around smart moves, winning hands, and strategically rearranging cards. 7 | 8 | Game Setup: 9 | 10 | A standard 52-card deck is used, consisting of 13 cards from each of the 4 suits: 11 | Spades (1), Hearts (2), Clubs (3), Diamonds (4). 12 | 13 | Initially, the deck is shuffled and divided between the two players. (The players will have same number of cards with them, although it is not guaranteed that they will have 26 cards each). 14 | Each player rearranges their shuffled cards before the game starts based on the card arrangement rules described below. 15 | A custom priority order for suits is provided. The suit number written first have higher priority as compared to that written at last. E.g., If the priority order is - "2, 1, 3, 4" - This means Hearts (2) have highest priority and Diamonds (4) have lowest priority. 16 | Card Values: 17 | 18 | 'A' represents 1. 19 | 20 | 'J' represents 11. 21 | 22 | 'Q' represents 12. 23 | 24 | 'K' represents 13. 25 | 26 | Remaining numeric values are same as that on the cards. 27 | 28 | Gameplay Rules: 29 | 30 | Vaishnavi plays first. 31 | On each turn, the player removes the top card from their deck and places it on the central stack, called as hand. 32 | From the second turn onwards: 33 | The newly drawn card is compared with the top card of the hand. 34 | The new card wins if it has same value with higher priority. 35 | If the new card wins: 36 | The player claims the entire hand. 37 | The hand is rearranged based on rearrangement rules (described below). 38 | The rearranged hand is then added to the bottom of the winner's deck. 39 | The winning player takes the next turn. 40 | If the new card does not win, it is simply placed on the top of the hand and play continues with the other player. 41 | Card Rearrangement Rule: 42 | 43 | Whenever a player wins the hand, they must rearrange the stack before adding it to their deck (this will also be done at the start): 44 | 45 | Cards are primarily sorted by non-decreasing card value. 46 | If multiple cards have the same value, they are sorted among themselves by suit priority (lower priority suit comes first). 47 | Game End Situation: 48 | 49 | The game continues until one of the players runs out of cards. 50 | The player who still has cards left is declared the winner. 51 | If both the players run out of cards at the same time, the result is TIE. 52 | Your Task: 53 | 54 | Given the starting deck of both players and suit priority, determine whether Vaishnavi wins the game or not if both players play optimally. 55 | 56 | Note: There will be no such case where the game is stuck in a never-ending loop. The game will always have end. 57 | 58 | Constraints 59 | 5 <= N <= 26 60 | 61 | C1, C2 € (A, J, Q, K, 2 .. 10) 62 | 63 | S1, S2 € (1, 2, 3, 4) 64 | 65 | Input 66 | The first line has an integer N, indicating the number of cards in each player's deck. 67 | 68 | Lines 2 to N+1 each have four integers: C1, S1, C2, and S2, separated by spaces, where 69 | 70 | C1 is the value for the card which is distributed to player 1 71 | S1 is the suit number for the card which is distributed to player 1 72 | C2 is the value for the card which is distributed to player 2 73 | S2 is the suit number for the card which is distributed to player 2 74 | Line N+2 lists four integers that set suit priorities from highest to lowest. 75 | 76 | Output 77 | {WINNER, LOSER, TIE} 78 | 79 | Time Limit (secs) 80 | 1 81 | 82 | Examples 83 | Example 1 84 | 85 | Input 86 | 87 | 5 88 | 89 | K 2 Q 4 90 | 91 | A 4 4 1 92 | 93 | 2 2 Q 1 94 | 95 | 4 2 3 1 96 | 97 | 6 1 5 2 98 | 99 | 1 2 3 4 100 | 101 | Output 102 | 103 | TIE 104 | 105 | Explanation 106 | 107 | Vaishnavi (Player 1) and Suraj (Player 2) have the following cards when arranged - 108 | 109 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6e4ea0bd:image1.png 110 | 111 | Here, when players play optimally starting with Vaishnavi, 112 | there is one situation where the cards need to be checked. 113 | This is when the hand contains 4 of Spades. When Vaishnavi's turn, she draws 4 of Hearts but cannot win the hand since Hearts have less priority as compared to Spades. Till the end, no one of two wins the hand and remains with zero cards in their respective decks. Hence the answer - "TIE". 114 | Example 2 115 | 116 | Input 117 | 118 | 5 119 | 120 | K 2 Q 4 121 | 122 | A 4 4 1 123 | 124 | 2 2 Q 1 125 | 126 | 4 2 3 1 127 | 128 | 5 1 5 2 129 | 130 | 3 2 1 4 131 | 132 | Output 133 | 134 | WINNER 135 | 136 | Explanation 137 | 138 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6e4ea0bd:image2.png 139 | 140 | Here, there will be one situation when the hand will contain 4 of Spades and Vaishnavi will draw 4 of Hearts. Here, Hearts have greater priority as compared to Spades, hence, the hand belongs to Vaishnavi, and she will now have 7 cards in here deck. Next, when Vaishnavi's turn, she draws 5 of Spades whereas Suraj draws 5 of Hearts. This hand will be claimed by Suraj for the greater priority of Hearts than Spades and thus, Suraj will have 4 cards with him. When the game continues, there will be no situation where either of both can win and eventually they will lose their cards. At last, when Suraj loses his all cards, Vaishnavi will have 2 with her. Hence she will be the "WINNER". 141 | 142 | Example 3 143 | 144 | Input 145 | 146 | 5 147 | 148 | K 2 Q 4 149 | 150 | A 4 4 1 151 | 152 | 6 2 Q 1 153 | 154 | 4 2 3 1 155 | 156 | 5 1 5 2 157 | 158 | 2 4 3 1 159 | 160 | Output 161 | 162 | LOSER 163 | 164 | Explanation 165 | 166 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6e4ea0bd:image3.png 167 | 168 | Here, there comes one situation where cards will be checked. 169 | This is when the hand contains 4 of Hearts and Suraj draws 4 of Spades. 170 | But because of the priorities, Suraj cannot claim the hand and the game continues. 171 | Next situation will contain 5 of Spades at the top of the hand and Suraj draws 5 of Hearts. 172 | Here, Suraj claims the hand and the hand will be added to his deck. 173 | At last, Vaishnavi runs out of her cards and Suraj will have some with him. 174 | This situation leads Vaishnavi to lose and hence the answer - "LOSER". 175 | ''' 176 | -------------------------------------------------------------------------------- /RealPage/MCQ/MCQ.md: -------------------------------------------------------------------------------- 1 | MCQS: 2 | 1. **What will happen if you try to compile the following Java code?** 3 | 4 | ```java 5 | public class MyClass extends S1, S2 implements I1, I2 { 6 | // class body 7 | } 8 | ``` 9 | 10 | Where: S1 and S2 are abstract classes. I1 and I2 are interfaces. 11 | 12 | Options: 13 | 14 | A) The code will compile successfully, and MyClass will inherit from 15 | both S1 and S2. 16 | 17 | B) The code will result in a compile-time error because Java does not 18 | support multiple inheritance of classes. 19 | 20 | C) The code will result in a runtime error because abstract classes 21 | cannot be extended together. 22 | 23 | D) The code will compile only if S2 is made an interface instead of an 24 | abstract class. 25 | 26 | **Correct Answer**: 27 | 28 | B) The code will result in a compile-time error because Java does not support multiple inheritance of classes. 29 | 30 | 2. Consider the following Java code: 31 | 32 | ```java 33 | String a = "String"; 34 | String b = new String("String"); 35 | String c = a; 36 | 37 | System.out.println(a == b); // Line 1 38 | System.out.println(a == c); // Line 2 39 | System.out.println(b.equals(c)); // Line 3 40 | ``` 41 | 42 | What will be the output of the above code? 43 | 44 | Options: 45 | 46 | A) true\ 47 | true\ 48 | true 49 | 50 | B) false\ 51 | true\ 52 | true 53 | 54 | C) 55 | 56 | false\ 57 | false\ 58 | true 59 | 60 | D) 61 | 62 | true\ 63 | false\ 64 | false 65 | 66 | **Correct Answer**: B 67 | 68 | 3. **What happens if a local variable is declared without initialization and 69 | then is accessed in Java?** 70 | 71 | ``` java 72 | public class Test { 73 | public static void main(String[] args) { int x; // local variable declared but not initialized 74 | System.out.println(x); // accessing x 75 | } 76 | } 77 | ``` 78 | 79 | Options: 80 | 81 | A) The code compiles and prints 0 as the default value of int. 82 | 83 | B) The code compiles and prints null. 84 | 85 | C) The code results in a compile-time error because local variables 86 | must be initialized before use. 87 | 88 | D) The code results in a runtime exception due to uninitialized 89 | variable. 90 | 91 | **Correct Answer**: C) 92 | 93 | 4. **Consider the following Java class:** 94 | 95 | ``` java 96 | public class Test { 97 | int x; // instance variable 98 | String str; // instance variable 99 | 100 | public static void main(String[] args) { 101 | Test obj = new Test(); // default constructor 102 | System.out.println(obj.x); 103 | System.out.println(obj.str); 104 | } 105 | 106 | } 107 | ``` 108 | 109 | What will be the output? 110 | 111 | Options: 112 | 113 | A) 114 | 0 115 | null 116 | 117 | B) Compile-time error due to uninitialized variables 118 | 119 | C) 120 | Garbage value\ 121 | Garbage value 122 | 123 | D) 124 | null\ 125 | 0 126 | 127 | **Correct Answer**: A) 128 | 0\ 129 | null 130 | 131 | 5) **Consider the following Java code:** 132 | 133 | ``` java 134 | public class Test { 135 | public static void main(String[] args) { 136 | try { 137 | int[] arr = new int[]{1, 2, 3}; 138 | int sum = 0; 139 | for (int i = 1; i < 4; i++) { 140 | sum += arr[i]; 141 | } 142 | System.out.println(sum); 143 | } catch (Exception e) { 144 | System.out.println("Exception caught"); 145 | } catch (IndexOutOfBoundsException e) { 146 | System.out.println("IndexOutOfBounds caught"); 147 | } 148 | } 149 | } 150 | ``` 151 | 152 | What will be the output? Options: 153 | 154 | A) 5 155 | 156 | B) Exception caught 157 | 158 | C) IndexOutOfBounds caught 159 | 160 | D) Compile-time error due to unreachable catch block 161 | 162 | **Correct Answer**: 163 | 164 | D) Compile-time error due to unreachable catch block 165 | 166 | 167 | 6) **Given the following Java class:** 168 | 169 | ``` java 170 | public class Fizz { 171 | String buzz; // default (package-private) access 172 | protected String woof; // protected access 173 | } 174 | ``` 175 | What is the accessibility of the attributes buzz and woof? Options: 176 | 177 | A) Both buzz and woof are accessible only within the same class. 178 | 179 | B) buzz is accessible within the same package, woof is accessible 180 | within the same package and subclasses (even outside the package). 181 | 182 | C) Both buzz and woof are public and accessible everywhere. 183 | 184 | D) buzz is private, and woof is protected, so both are only accessible 185 | in the same class and subclasses. 186 | 187 | **Correct Answer**: 188 | B) buzz is accessible within the same package 189 | (default/package-private access), woof is accessible within the same 190 | package and also in subclasses even if they are in different packages 191 | (protected access). 192 | 193 | 7) **Consider the following class definition:** 194 | 195 | ```java 196 | class Rectangle { 197 | int width; 198 | int length; 199 | 200 | public Rectangle(int width, int length) { 201 | this.width = width; 202 | this.length = length; 203 | } 204 | } 205 | ``` 206 | 207 | You want the following statement to print a meaningful output: 208 | 209 | ```System.out.println(new Rectangle());``` 210 | 211 | **Which method must be implemented in the Rectangle class to achieve this?** 212 | 213 | Options: 214 | 215 | A) display() 216 | 217 | B) printDetails() 218 | 219 | C) describe() 220 | 221 | D) toString() 222 | 223 | **Correct Answer**: 224 | D) toString() 225 | 226 | 8) **Which of the following cannot be inherited by a subclass in Java?** 227 | 228 | Options: 229 | 230 | A) protected int var1; 231 | 232 | B) static int var1; 233 | 234 | C) public abstract int var; 235 | 236 | D) private int var1; 237 | 238 | **Correct Answer**: 239 | D) private int var1; 240 | 241 | 9) **Which Java interface allows an object to be saved to a stream and 242 | then reconstructed later, even in a separate JVM?** 243 | 244 | Options: A) Readable B) Serializable C) Cloneable D) Externalizable 245 | 246 | **Correct Answer**: B) Serializable 247 | 248 | 10) **Question: To ensure that the sum() function (foo()) of class Bar is 249 | implemented separately in every subclass, how should it be declared 250 | in the base class? Options:** 251 | 252 | 253 | A) abstract foo() 254 | B) public synchronized foo() 255 | C) protected abstract foo() 256 | D) protected() foo() 257 | 258 | **Correct Answer**: C) protected abstract foo() 259 | -------------------------------------------------------------------------------- /OffCampus/Codevita/Zone2/pathfinder.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Path Finder 3 | Problem Description 4 | Lilly, being wise and clever, always thinks in the most optimal way. One day, feeling bored, she drew a grid filled with random values. She then set herself a goal to achieve using this grid. 5 | 6 | Lilly starts at the source cell and wants to reach the destination cell. From any given cell, she can move to one of its 8 neighbouring cells that has the maximum value. Lily can move to the neighbouring cell if and only if the neighbour cell has the max value. If it does not have the max value, first she must make it maximum by adding some value and then move to it. Additionally, there are K blocked cells that she cannot enter, and she will not consider these at all for stepping in and the blocked cells cannot be considered for calculating the maximum value among the neighbours. Note that if the current cell has the maximum value among all its neighbours, then she will try to move to a neighbouring cell by increasing its value beyond the current cell's value. Also, note that the values we add are temporary i.e., after adding some value and moving to that cell, the value of that cell becomes the original value. 7 | 8 | Lilly named this challenge as "Path Finder" since it tests both her strategic thinking and ability to find the most efficient path through the grid. 9 | 10 | Note: Current cell must have only one highest-value neighbor i.e., the cell Lilly wants to shift. 11 | 12 | Constraints 13 | 2 <= N, M <= 20 14 | 15 | 0 <= K <= 10 16 | 17 | 1 < Units of data in containers < 100 18 | 19 | Source and destination cells will never be blocked. 20 | 21 | Input 22 | First line consists of two space separated integers N and M representing the size of the grid. 23 | 24 | Next N lines, each consists of M space separated integers, representing numbers in the grid cells. 25 | 26 | Line N+1 consist of two space separated integers, indicating Lilly's current location. 27 | 28 | Line N+2 consists of two space separated integers, specifying the destination cell where Lilly want to reach. 29 | 30 | Next line consists of an integer K denoting the number of blocked cells. 31 | 32 | Next K lines each consists of two space separated integers denoting the indices of blocked cells. 33 | 34 | The indexes are one basis. 35 | 36 | Output 37 | Print a single integer denoting the minimum value Lilly must add to reach the destination cell. 38 | 39 | Time Limit (secs) 40 | 1 41 | 42 | Examples 43 | Example 1 44 | 45 | Input 46 | 47 | 4 4 48 | 49 | 1 2 3 4 50 | 51 | 5 6 7 8 52 | 53 | 9 10 11 12 54 | 55 | 13 14 15 16 56 | 57 | 2 2 58 | 59 | 4 1 60 | 61 | 2 62 | 63 | 3 1 64 | 65 | 1 4 66 | 67 | Output 68 | 69 | 5 70 | 71 | Explanation 72 | 73 | Lilly's current location is at cell (2, 2), and she needs to reach cell (4, 1). Consider two possible paths - 74 | 75 | Path 1: (2, 2) -> (3, 2) -> (4, 1) and Path 2: (2, 2) -> (3, 1) -> (4, 1) 76 | 77 | To move from (2, 2) to (3, 2), the next cell must have a value greater than all its neighbours, so we need to add 2. Then, moving from (3, 2) to (4, 1) requires adding 3 more, giving a total of 5. Similarly, the other path also requires a total value addition of 5. However, since cell (3, 1) is blocked, Lilly must take the first path, which still results in the minimum total value added. 78 | 79 | Example 2 80 | 81 | Input 82 | 83 | 6 6 84 | 85 | 1 17 18 20 11 10 86 | 87 | 3 17 15 18 16 15 88 | 89 | 10 11 20 6 8 3 90 | 91 | 18 18 5 11 4 16 92 | 93 | 3 4 8 17 18 20 94 | 95 | 3 17 15 18 16 15 96 | 97 | 1 1 98 | 99 | 3 4 100 | 101 | 3 102 | 103 | 2 1 104 | 105 | 2 2 106 | 107 | 5 5 108 | 109 | Output 110 | 111 | 18 112 | 113 | Explanation 114 | 115 | Lilly starts at cell (1, 1) and needs to reach cell (3, 4). One possible path she can take is (1, 1) -> (1, 2) -> (1, 3) -> (1, 4) -> (2, 4) -> (3, 4), which results in a minimum total value addition of 18. 116 | 117 | Break up of calculations - 118 | 119 | For moving from (1, 1) to (1, 2) nothing must be added, because among those unblocked neighbours of (1, 1), the neighbour (1, 2) is having maximum. So simply move to it. 120 | 121 | Again, moving from (1, 2) to (1, 3) and then to (1, 4) costs nothing as they are already largest neighbours. 122 | 123 | Moving from (1, 4) to (2, 4) results in a cost of 3 and finally moving from (2, 4) to (3, 4) results in a cost of 15. 124 | 125 | Hence the total value to be added is 3 + 15 = 18. 126 | ''' 127 | 128 | import heapq 129 | 130 | directions = [ 131 | (-1, 0), (1, 0), (0, -1), (0, 1), 132 | (-1, -1), (-1, 1), (1, -1), (1, 1) 133 | ] 134 | 135 | 136 | def find_min_path(grid, start, end, blocked_set): 137 | n, m = len(grid), len(grid[0]) 138 | 139 | start_r, start_c = start[0] - 1, start[1] - 1 140 | dest_r, dest_c = end[0] - 1, end[1] - 1 141 | 142 | pq = [(0, start_r, start_c)] 143 | dist = [[float('inf')] * m for _ in range(n)] 144 | dist[start_r][start_c] = 0 145 | 146 | while pq: 147 | cost, i, j = heapq.heappop(pq) 148 | 149 | if (i, j) == (dest_r, dest_c): 150 | return cost 151 | 152 | if cost > dist[i][j]: 153 | continue 154 | 155 | curr_val = grid[i][j] 156 | 157 | for dx, dy in directions: 158 | ni, nj = i + dx, j + dy 159 | 160 | if not (0 <= ni < n and 0 <= nj < m): 161 | continue 162 | 163 | if (ni + 1, nj + 1) in blocked_set: 164 | continue 165 | 166 | next_val = grid[ni][nj] 167 | 168 | max_other_neighbor = -1 169 | 170 | for dx_o, dy_o in directions: 171 | onr, onc = i + dx_o, j + dy_o 172 | 173 | if (onr, onc) != (ni, nj) and 0 <= onr < n and 0 <= onc < m and (onr + 1, onc + 1) not in blocked_set: 174 | max_other_neighbor = max(max_other_neighbor, grid[onr][onc]) 175 | 176 | blocking_value = max(curr_val, max_other_neighbor) 177 | 178 | required_value = blocking_value + 1 179 | 180 | add_cost = max(0, required_value - next_val) 181 | 182 | new_cost = cost + add_cost 183 | 184 | if new_cost < dist[ni][nj]: 185 | dist[ni][nj] = new_cost 186 | heapq.heappush(pq, (new_cost, ni, nj)) 187 | 188 | return -1 189 | 190 | N, M = map(int, input().split()) 191 | grid = [] 192 | for _ in range(N): 193 | grid.append(list(map(int, input().split()))) 194 | start_r, start_c = map(int, input().split()) 195 | dest_r, dest_c = map(int, input().split()) 196 | K = int(input()) 197 | blocked = set() 198 | for _ in range(K): 199 | r, c = map(int, input().split()) 200 | blocked.add((r, c)) 201 | print(find_min_path(grid, (start_r, start_c), (dest_r, dest_c), blocked)) -------------------------------------------------------------------------------- /OffCampus/TVSEpic/Coding/Maximize_Graph_Score_By_Removing_Edges.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | # 🚀 Maximize Graph Score by Removing Edges 4 | 5 | ## 🧩 Problem Statement 6 | 7 | You are given an **undirected** graph with `N` nodes (numbered from `0` to `N-1`) and `M` edges. Additionally, you are given an integer `K`, 8 | which specifies the exact number of **edges that must be removed** from the graph. 9 | 10 | The **"score"** of the graph is calculated as: 11 | 12 | > For each node `i` (0 ≤ i < N), count the number of **other nodes** that can be reached from node `i` via any path in the graph. 13 | > The **total score** is the sum of these reachable counts for **all nodes**. 14 | 15 | Your task is to **choose exactly K edges** to remove from the graph such that the **total score** is **maximized**. 16 | 17 | --- 18 | 19 | ## 📥 Input Format 20 | 21 | - The first line contains three space-separated integers: `N`, `M`, and `K` 22 | - `N`: Number of nodes (0 to N-1) 23 | - `M`: Number of edges 24 | - `K`: Number of edges to remove 25 | - The next `M` lines each contain two integers `u` and `v` representing an undirected edge between `u` and `v`. 26 | 27 | --- 28 | 29 | ## 📤 Output Format 30 | 31 | - Print a single integer — the **maximum score** possible after removing exactly `K` edges. 32 | 33 | ## 🔎 Sample Input 34 | 35 | 4 2 2 36 | 0 1 37 | 1 2 38 | 39 | 40 | ### Sample Output 41 | 0 42 | 43 | 44 | Sample Test Case-2: 45 | 46 | Input: 47 | 12 11 3 48 | 0 1 49 | 1 2 50 | 2 3 51 | 3 4 52 | 4 2 53 | 5 6 54 | 6 7 55 | 7 8 56 | 8 6 57 | 9 10 58 | 10 11 59 | 60 | Output: 61 | 34 62 | 63 | ## 📊 Constraints 64 | 1 <= N <= 10^3 65 | 1 <= M <= min(10^3, N*(N-1)/2) 66 | 0 <= K <= M 67 | 0 <= u, v < N 68 | 69 | */ 70 | import java.util.*; 71 | 72 | class DisjointSet { 73 | private final int n; 74 | private final int[] parent; 75 | private final int[] size; 76 | private int cycleCount; 77 | 78 | private void init() { 79 | for (int i = 0; i < n; i++) { 80 | this.parent[i] = i; 81 | this.size[i] = 1; 82 | } 83 | } 84 | 85 | public DisjointSet(int n) { 86 | this.n = n; 87 | this.parent = new int[n]; 88 | this.size = new int[n]; 89 | this.cycleCount = 0; 90 | init(); 91 | } 92 | 93 | public int findUParent(int node) { 94 | if (node == parent[node]) { 95 | return node; 96 | } 97 | 98 | return parent[node] = findUParent(parent[node]); 99 | } 100 | 101 | public void unionBySize(int u, int v) { 102 | int pu = findUParent(u); 103 | int pv = findUParent(v); 104 | 105 | if (pu == pv) { 106 | cycleCount++; 107 | return; 108 | } 109 | 110 | if (size[pu] <= size[pv]) { 111 | // attach smaller component to larger component 112 | parent[pu] = pv; 113 | size[pv] += size[pu]; 114 | } else { 115 | parent[pv] = pu; 116 | size[pu] += size[pv]; 117 | } 118 | } 119 | 120 | public int getCycleCount() { 121 | return cycleCount; 122 | } 123 | 124 | public int componentsScore() { 125 | 126 | // This calculcates aggregate component score for entire DSU 127 | int score = 0; 128 | for (int node = 0; node < n; node++) { 129 | int boss = findUParent(node); 130 | if (boss == node) { 131 | // get the component score bro 132 | score += size[boss] * (size[boss] - 1); // (number of reachable pairs) 133 | } 134 | } 135 | return score; 136 | } 137 | 138 | public int[] getSizeArray() { 139 | return size; 140 | } 141 | 142 | } 143 | 144 | public class Maximize_Graph_Score_By_Removing_Edges { 145 | private static int maxScore; 146 | 147 | private static void dfs(int idx, int removed, int k, int n, int[][] edges, List toRemove) { 148 | if (removed == k) { 149 | DisjointSet dsu = new DisjointSet(n); 150 | Set removedSet = new HashSet<>(toRemove); 151 | for (int i = 0; i < edges.length; i++) { 152 | if (!removedSet.contains(i)) { 153 | // If not removed then add this edge to DSU 154 | dsu.unionBySize(edges[i][0], edges[i][1]); 155 | } 156 | } 157 | maxScore = Math.max(maxScore, dsu.componentsScore()); 158 | return; 159 | } 160 | 161 | if (idx >= edges.length) 162 | return; 163 | 164 | // Try removing this edge 165 | toRemove.add(idx); 166 | dfs(idx + 1, removed + 1, k, n, edges, toRemove); 167 | toRemove.remove(toRemove.size() - 1); 168 | 169 | // Or don't remove 170 | dfs(idx + 1, removed, k, n, edges, toRemove); 171 | } 172 | 173 | // May be i thought this would help not sure if this greedy approach works 174 | // private static int getMaxScoreAfterKRemovals(int n, int m, int k, int[][] edges) { 175 | // // Create a DSU 176 | // DisjointSet dsu = new DisjointSet(n); 177 | 178 | // for (int[] edge : edges) { 179 | // int u = edge[0]; 180 | // int v = edge[1]; 181 | 182 | // dsu.unionBySize(u, v); 183 | // } 184 | 185 | // // now get number of cycles and remaining value of k 186 | // k -= dsu.getCycleCount(); 187 | 188 | // if (k == 0) { 189 | // return dsu.componentsScore(); // all components can be included as it is 190 | // } 191 | 192 | // // Otherwise sort the sizes array and reduce 193 | // List sizesSorted = Arrays.stream(dsu.getSizeArray()) 194 | // .filter(x -> x != 1) 195 | // .boxed() 196 | // .collect(Collectors.toList()); 197 | 198 | // for(int i = 0 ; i < sizesSorted.size() ; i++){ 199 | 200 | // if(k <= 0) break; 201 | // int val = sizesSorted.get(i); 202 | // if (val - 1 <= k) { 203 | // sizesSorted.set(i, 0); 204 | // k -= (val - 1); 205 | // } 206 | 207 | 208 | // } 209 | 210 | // int maxi = 0; 211 | 212 | // for(int i = 0 ; i < sizesSorted.size() ; i++){ 213 | // int s = sizesSorted.get(i); 214 | // if(s == 0) continue; 215 | // maxi += s * (s - 1); 216 | // } 217 | 218 | // return maxi; 219 | 220 | // } 221 | 222 | public static void main(String[] args) { 223 | int n, m, k; 224 | int[][] edges; 225 | try (Scanner sc = new Scanner(System.in)) { 226 | n = sc.nextInt(); 227 | m = sc.nextInt(); 228 | k = sc.nextInt(); 229 | 230 | edges = new int[m][2]; 231 | 232 | for (int i = 0; i < m; i++) { 233 | edges[i][0] = sc.nextInt(); 234 | edges[i][1] = sc.nextInt(); 235 | } 236 | 237 | } 238 | 239 | maxScore = 0; 240 | dfs(0, 0, k, n, edges, new ArrayList<>()); 241 | System.out.println(maxScore); 242 | 243 | // Approach-ii) 244 | // System.out.println(getMaxScoreAfterKRemovals(n,m,k,edges)); 245 | 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /Caspex/Coding/Old Questions/programming questions.txt: -------------------------------------------------------------------------------- 1 | You are given an array A of size n containing positive integers, along with another array X of size m that specifies 2 | the indices of elements to be dropped from array A. 3 | 4 | Your task is to remove the elements at the specified indices from array A and then print the modified array as output. 5 | 6 | Constraints: 7 | ------------ 8 | 1 ≤ n ≤ 10^4 9 | 10 | 1 ≤ m ≤ 10^4 11 | 12 | 1 ≤ A[i] ≤ 10^6 13 | 14 | All the elements of the second array of size M should be distinct. 15 | 16 | The index of the elements in the array start from 0 17 | 18 | Any elements of array X cannot be negitive. 19 | 20 | 21 | Input Format: 22 | -------------- 23 | The first line of the input accepts an integer displaying the size of the array(n) 24 | The second line of the input accepts the elements of the array of size n. each separated by a space 25 | The third line of the input accepts an integer displaying the size of the array(m). 26 | The fourth line of input accepts the elements of the array of size m. each separated by a space. These elements contains consists of the indices we want to drop from the main array which is of size n. 27 | 28 | Output Format: 29 | -------------- 30 | A single line of output displays the array after dropping the elements. 31 | 32 | Sample Input 1: 33 | --------------- 34 | 4 35 | 1 2 3 4 36 | 2 37 | 2 3 38 | 39 | Sample Output 1: 40 | ---------------- 41 | 1 2 42 | 43 | Explanation 44 | ------------ 45 | The First line of input creates an array of size 4. The elements of this array is mentioned in the second line of input 46 | i.e.[1,2,3,4]. The third line of input is an array of size 2 which means that 2 elements from the array A need to be 47 | dropped . The fourth line of input contains the array( [2,3]) which displays that the elements of indices 2 and 3 need 48 | to be dropped from the main array([1,2,3,4]). 49 | The final output is array:[1,2] 50 | 51 | Sample Input 2: 52 | --------------- 53 | 6 54 | 3 4 5 6 3 2 55 | 1 56 | 2 57 | 58 | Sample Output 2: 59 | ---------------- 60 | 3 4 6 3 2 61 | 62 | Explanation 63 | ----------- 64 | The First line of input creates an array of size 6. The elements of this array is mentioned in the second line of input 65 | i.e.[3,4,5,6,3,2]. The third line of input is an array of size 1 which means that 1 elements from the array needs to 66 | be 67 | dropped . The fourth line of input contains the array( [2]) which displays that the elements of indices 2 need to be 68 | dropped from the main array([3,4,5,6,3,2]). 69 | The final output is array:[3,4,6,3,2] 70 | 71 | 72 | 73 | ======================================================================================================================== 74 | 75 | A University named "XYZ" sends the question papers for the different subjects to different colleges in a zipped file 76 | along with a secret key to access them. 77 | 78 | The Dean appoints squad to different colleges and gives them the following cipher algorithm to be used to find out the 79 | password required to open the zip file: 80 | 81 | i)Take the question paper’s name P and the secret key K (which can be positive or negative). 82 | ii)Displace all the lowercase English alphabets present in P by K.All the uppercase alphabets, numbers, spaces, and 83 | special characters are retained as it is. 84 | iii)If K is positive, displace to the right and if K is negative, displace to the left. 85 | iV)The lower limit and upper limit of the character's ASCII value generated after K displacement is 65 and 126. 86 | V)During right displacement, if the value exceeds 126,then start again from 65. while during left displacement, if the 87 | value goes back from 126. 88 | 89 | The squads perform these steps to find out the password required to open the file and take out the printouts to conduct 90 | the examination. 91 | 92 | write a program by reading the input from STDIN and the output from STDOUT you should not write arbitary strings while 93 | reading the input and while printing as these contribute to the standard output. 94 | 95 | Constraints: 96 | ------------- 97 | i)P should not contain more than 50 characters. 98 | iI)-50 ≤ K ≤ 50 99 | 100 | Input Format: 101 | ------------- 102 | The first line contains the question paper's name P. 103 | The second line contains the secret key K. 104 | 105 | Output Format: 106 | -------------- 107 | The output contains a single string which is the password required to open the zip file. 108 | 109 | Sample Input 1: 110 | --------------- 111 | Operating Systems 112 | -40 113 | 114 | Sample Output 1: 115 | ---------------- 116 | OH(JwLAF) SQKL(EK 117 | 118 | Explanation-1: 119 | -------------- 120 | Given question paper name P is "Operating Systems" and k Value is -40 121 | 122 | 123 | consider the the table given below: 124 | 125 | | Character | ASCII (Before) | ASCII (After) | Result Character | Remarks | 126 | | --------- | --------------- | --------------|------------------|------------------------------------------| 127 | | O | No displacement | - | O | Uppercase alphabet, retained as it is | 128 | | p | 112 | 72 | H | | 129 | | e | 101 | 61 | { | It is below 65, so going back from 126 | 130 | | r | 114 | 74 | J | | 131 | | a | 97 | 57 | W | It is below 65, so going back from 126 | 132 | | t | 116 | 76 | L | | 133 | | i | 105 | 65 | A | | 134 | | n | 110 | 70 | F | | 135 | | g | 103 | 63 | } | It is below 65, so going back from 126 | 136 | | | No displacement | - | | White space | 137 | | S | No displacement | - | S | Uppercase alphabet, retained as it is | 138 | | y | 121 | 81 | Q | | 139 | | s | 115 | 75 | K | | 140 | | t | 116 | 76 | L | | 141 | | e | 101 | 61 | { | | 142 | | m | 109 | 69 | E | | 143 | | s | 115 | 75 | K | | 144 | 145 | 146 | 147 | Sample Input 2: 148 | -------------- 149 | X@DF* 150 | 20 151 | 152 | Sample Output 2: 153 | --------------- 154 | X@DF* 155 | 156 | 157 | Explanation 2: 158 | -------------- 159 | 160 | From the same input2, the given question paper name is "X@DF*" and the K value is 20. 161 | Here X is an Upper case alphabet, @ is a specila character ,D, F is upper case alphabets and * is aspecial character. 162 | so, all the characters are retained as it is. -------------------------------------------------------------------------------- /OffCampus/Codevita/Zone2/foldpaper.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Folded Sheet 3 | Problem Description 4 | Codesheeta is a renowned manufacturer of bed sheets. Will the branding team play a role in supporting an environment with reduced pollution? 5 | 6 | All sheets produced by codesheeta will feature the company's branding logo in multiple locations. As a result, regardless of how the sheet is folded, the logo will remain visible at both the top and bottom. 7 | 8 | As part of Codesheeta' s initiative to promote a low-pollution environment, the branding team has opted to determine the optimal method for folding the sheet. Their goal is to identify precise locations for logo placement so that, upon folding, the logo appears on both the top and bottom surfaces, thereby minimizing unnecessary duplication and reducing excess printing. 9 | 10 | A sheet is described as consisting of rows and columns with unit-sized cells. Each cell is numbered,starting from top left, going rightwards on each row. Horizontal lines separating the rows are referred to as h1, h2, ..., hn from top to bottom, while vertical lines separating the columns are designated as v1, v2, ..., vn from right to left. The sheet may be folded along either the vertical or horizontal lines. It is important to note that these folding lines are relative rather than absolute, meaning their order may change following a fold. During a vertical fold, the right section of the sheet is placed over the left, whereas a horizontal fold involves moving the bottom section over the top. 11 | 12 | The following images illustrate a complete sheet and demonstrate its folding along various lines. 13 | 14 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6c451c9c:image1.png 15 | 16 | A detailed folding instruction will be provided outlining the process used to fold and package the bed sheet. 17 | 18 | Based on the dimensions and folding guidelines of the sheet, identify the specific cells designated for logo placement. 19 | 20 | Constraints 21 | 3<= R, C <= 25 22 | 23 | Input 24 | The first line contains two integers, R and C, for the bed sheet's rows and columns. 25 | 26 | Next line consists of instruction sequence to be applied sequentially, as explained above. Refer examples section for better understanding. 27 | 28 | Output 29 | Print two integers, representing the Top and bottom cells where logo needs to be printed. 30 | 31 | Time Limit (secs) 32 | 1 33 | 34 | Examples 35 | Example 1 36 | 37 | Input 38 | 39 | 4 4 40 | 41 | v2 h3 v1 h2 h1 42 | 43 | Output 44 | 45 | 5 1 46 | 47 | Explanation 48 | 49 | The full sheet will be depicted as below. 50 | 51 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6c451c9c:image2.png 52 | 53 | Applying the folding instructions. 54 | 55 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6c451c9c:image3.png 56 | 57 | From above we can see that cells 5 are at top and 1 at bottom. Printing logo on them is enough. So, the output 5 1 58 | 59 | Example 2 60 | 61 | Input 62 | 63 | 4 2 64 | h1 v1 h2 h1 65 | 66 | Output 67 | 68 | 5 7 69 | 70 | Explanation 71 | 72 | Below image depicts the sheet and the folding instruction applied. 73 | 74 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6c451c9c:image4.png 75 | 76 | com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@6c451c9c:image5.png 77 | 78 | The images above indicate that cells 5 and 7 will be positioned at the top and bottom, respectively; therefore, the output will be 5 7. 79 | 80 | 4 4 81 | v1 h3 v2 v1 h2 h1 82 | ''' 83 | 84 | 85 | R, C = map(int, input().split()) 86 | instructions = input().split() 87 | sheet = [] 88 | count = 1 89 | for i in range(R): 90 | row = [] 91 | for j in range(C): 92 | row.append([count]) # each cell is a list: [top, ..., bottom] 93 | count += 1 94 | sheet.append(row) 95 | 96 | for inst in instructions: 97 | typ = inst[0] 98 | idx = int(inst[1:]) 99 | 100 | if typ == 'v': # right over left 101 | left = [row[:idx] for row in sheet] 102 | right = [row[idx:] for row in sheet] 103 | 104 | # flip right half horizontally (columns mirror) 105 | for r in right: 106 | r.reverse() 107 | 108 | # print(" Left:") 109 | # for row in left: 110 | # print(" ", row) 111 | # print(" Right:") 112 | # for row in right: 113 | # print(" ", row) 114 | 115 | 116 | new_left = [] 117 | for i in range(len(sheet)): 118 | new_row = left[i].copy() 119 | for j in range(len(right[0])): 120 | target_col = idx - j - 1 121 | right_cell = right[i][j] 122 | rotated = right_cell[::-1] 123 | if target_col >= 0: 124 | 125 | new_row[target_col] = rotated + new_row[target_col] 126 | else: 127 | 128 | new_row.insert(0, rotated) 129 | new_left.append(new_row) 130 | sheet = new_left 131 | 132 | elif typ == 'h': 133 | top = sheet[:idx] 134 | bottom = sheet[idx:] 135 | 136 | # flip bottom vertically (rows mirror) 137 | bottom.reverse() 138 | 139 | # print(" Top:") 140 | # for row in top: 141 | # print(" ", row) 142 | # print(" Bottom:") 143 | # for row in bottom: 144 | # print(" ", row) 145 | 146 | # merge bottom onto top, handling extra rows in bottom 147 | new_top = [] 148 | 149 | for i in range(len(bottom)): 150 | target_row = idx - i - 1 151 | bottom_row = bottom[i] 152 | if target_row >= 0: 153 | # merge each cell in that row 154 | merged_row = [] 155 | for j in range(len(bottom_row)): 156 | rotated_cell = bottom_row[j][::-1] # rotate cell stack 157 | merged_row.append(rotated_cell + top[target_row][j]) 158 | 159 | 160 | final_rows = max(len(top), len(bottom)) 161 | result_rows = [] 162 | for r_index in range(final_rows): 163 | 164 | top_row_idx = r_index - (final_rows - len(top)) 165 | 166 | bottom_row_idx = r_index - (final_rows - len(bottom)) 167 | 168 | cols = len(sheet[0]) if sheet else (len(top[0]) if top else len(bottom[0])) 169 | row_cells = [] 170 | for c in range(cols): 171 | top_cell = None 172 | bottom_cell = None 173 | if 0 <= top_row_idx < len(top): 174 | top_cell = top[top_row_idx][c] 175 | if 0 <= bottom_row_idx < len(bottom): 176 | 177 | bottom_cell = bottom[bottom_row_idx][c][::-1] 178 | if bottom_cell is not None and top_cell is not None: 179 | row_cells.append(bottom_cell + top_cell) 180 | elif bottom_cell is not None: 181 | row_cells.append(bottom_cell) 182 | else: 183 | row_cells.append(top_cell) 184 | result_rows.append(row_cells) 185 | sheet = result_rows 186 | 187 | # print(f" After folding {inst}:") 188 | # for row in sheet: 189 | # print(" ", row) 190 | # print("-----") 191 | 192 | # After all folds, final sheet should be 1x1 193 | final_stack = sheet[0][0] 194 | top_cell = final_stack[0] 195 | bottom_cell = final_stack[-1] 196 | print(top_cell, bottom_cell) 197 | -------------------------------------------------------------------------------- /OpenText/Old Questions/opentext questions.txt: -------------------------------------------------------------------------------- 1 | Slot-1 2 | 3 | Question 1 4 | 5 | Design a way to sort the list of positive integers in descending order according to frequency of the elements.The elements with higher frequency come before those with lower frequency .Elements with the same frequency come in the same order as they appear in the given list. 6 | 7 | input 8 | ----- 9 | The first line of the input consists of an integer -num, representing the number of elements in the list(N). 10 | The second line consists of N space separated integers representing the elements in the list. 11 | 12 | output 13 | ------ 14 | Print N space-separated integers representing the elements of the list sorted according to the frequency of elements present in the given list 15 | 16 | 17 | Example 18 | ------- 19 | 20 | input: 21 | 19 22 | 1 2 2 3 3 3 4 4 5 5 5 5 6 6 6 7 8 9 10 23 | 24 | output: 25 | 5 5 5 5 3 3 3 6 6 6 2 2 4 4 1 7 8 9 10 26 | 27 | Explanation: 28 | ------------ 29 | 30 | The element 5 has highest frequency. 31 | The elements 3 and 6 have same frequencies.So their original order has been maintained in the output. 32 | The frequencies of rest of elements will be found and arranged in a similar way . 33 | So the output will be : 5 5 5 5 3 3 3 6 6 6 2 2 4 4 1 7 8 9 10. 34 | 35 | 36 | 37 | 38 | ------------------------------------------------------------------------------------------------------------- 39 | 40 | Question 2 41 | 42 | 43 | The computer systems of N employees of a company are arranged in a row.A technical fault in the power supply has caused some of the systems to turn OFF while the others remain ON. The employees whose systems are OFF are unable to work.The company does not like to see 44 | employees sitting idle.So until the technical team can find the actual cause of the breakdown, the technical head has devised a temporary workaround for the OFF systems a ta minimum cost. They 45 | decide to connect all the OFF systems to the nearest ON system with the shortest possible length of cable. To make this happen, they 46 | calculate the distance of each system from the first system. 47 | 48 | Write an algorithm to help the technical head find the minimum length of cable they need to turn all the systems ON. 49 | 50 | Input 51 | ----- 52 | The first line of the input consists of an integer- systemState_size, 53 | representing the number of systems (N). 54 | The second line consists of N space-separated integers 55 | systemState[1],systemState[2]...systemState[N],representing the initial state of each system, ON (1)or OFF (0). 56 | The third line consists of an integer - dist_size, representing the number of distances (M). 57 | The last line consists of M space-separated integers- dist(1),dist(2),......,dis([M], representing the distance of each system from the first 58 | system. 59 | 60 | 61 | Output 62 | ------ 63 | Print an integer representing the minimum length of cable that the technical head needs to turn all the systems ON.If no cable is needed then print 0. 64 | 65 | Constraints 66 | ------------ 67 | 1<=systemState_ size, dist sizes <=10^5 68 | 1<=dist[i] < dist[i+1] <= 10^9 69 | 70 | 71 | Note 72 | ---- 73 | It is guaranteed that at least one system is 74 | ON and none of the systems are faulty. 75 | 76 | Example 77 | ------- 78 | Input: 79 | 3 80 | 100 81 | 3 82 | 156 83 | 84 | Output: 85 | 5 86 | 87 | Explanation: 88 | ------------ 89 | Length of cable required to connect the 2nd system to the 1st system = 4 90 | Length of cable required to connect the 3rdsystem to the 2nd system =1. 91 | Total length of cable =5(4+1). 92 | So the output is 5. 93 | 94 | 95 | 96 | 97 | ----------------------------------------------------------------------------------------------------------------- 98 | Question 3 99 | ---------- 100 | 101 | Mr.Woods, an electrician for Timberland city, has made some faulty connections on eight street lights.The errors cause a street light to go OFF if the street lights adjacent to that light were both ON 102 | (represented as 1)or both OFF (represented as 0) on the previous night. Otherwise, the light will go ON as normal. The two street lights at the end of the road have only a single adjacent street light, so the 103 | light at the end can be assumed to be always OFF. The state of the lights on a particular day is considered for the following day, not for the same day. 104 | 105 | Because of this fault, people are having difficulty driving on the road at night.They have filed a complaint to the head of the highway 106 | administration. Based on this complaint the head has ordered a report of the state of street lights after M days. 107 | 108 | 109 | Write an algorithm to output the state of the street lights after the given M days 110 | 111 | Input 112 | ------ 113 | The first line of input consists of an integer-currentState_ size, representing the number of street lights (N). 114 | The next line consists of N space-separated 115 | integers -currentState, representing the current state of the street lights(i.e.,either 0 or 1). 116 | The last line consists of an integer-days, representing the number of days (M). 117 | 118 | Output 119 | ------- 120 | Print eight space-separated integers representing the state of the street lights after M days. 121 | 122 | Constraints 123 | ------------ 124 | 1 <= days <= 10^6 125 | 126 | Example 127 | ------- 128 | Input: 129 | 8 130 | 1 1 1 0 1 1 1 1 131 | 2 132 | 133 | Output: 134 | 0 0 0 0 0 1 1 0 135 | 136 | 137 | Explanation: 138 | ------------ 139 | Adjacent to the street light at position 0 are street lights 0 ( assumption) and 1. So on the next day, it will be 1. 140 | Explanation: The street light at position 1 has its adjacent street lights both 1. So on the next day, it will be 0. 141 | The street light at position 2 had as one of its adjacent street lights 0 and the other one 1 . 142 | So the next day , it will be 1. 143 | The street light at position 3 is 0 and both its adjacent street lights are 1 .So the next day the street light 144 | at position 3 will be 0 only similarly , we can find the state of the remaining street lights for the next day. 145 | So the state of the street lights after the first day is 1 0 1 0 1 0 0 1. 146 | after two days , the state of the street lights is 0 0 0 0 0 1 1 0. 147 | 148 | --------------------------------------------------------------------------------------------------------------- 149 | Slot-2 150 | 151 | Question-1 152 | 153 | Mary is developing an application on the concepts of prime numbers and factorization Among N numbers of the list 154 | displayed on the application display , the application will highlight all the numbers that appear as many times on the 155 | display as the frequency of their prime factors. 156 | 157 | Write an algorithm to help Mary find all the numbers that appear as many times on the display as the frequency of their 158 | prime factors. 159 | 160 | Input: 161 | ------- 162 | The first line of the input consists of an integer num, representing the size of the list(N), 163 | the second line consists of N space separated integers representing the numbers displayed on the application display. 164 | 165 | Output: 166 | ------- 167 | Print M space-separated integers representing all the numbers that appears as many times on the display as the 168 | frequency of their prime factors in ascending order. if no such number is found in the given list then print -1. 169 | 170 | 171 | Constraints 172 | ------------ 173 | 0 < num <=10^5 174 | 175 | 0<= data <=10^6;where data represents a number on the display 176 | 177 | Example 178 | ------- 179 | input: 180 | 7 181 | 4 2 12 25 12 12 25 182 | 183 | output: 184 | 2 12 25 185 | 186 | Explanation: 187 | 2 has 1 prime factor. 188 | 12 has 3 prime factors: 2,2,3 189 | 25 has 2 prime factors: 5,5. 190 | 2 is present one time , 12 is present 3 times, and 25 is present 2 times in the given list 191 | so the output is [2,12,25] 192 | 193 | 194 | ------------------------------------------------------------------------------------------------------------------- 195 | 196 | Question 2 197 | 198 | In the game of chess, the queen can attack an opponent if the piece is located in the same row, same column, or same 199 | diagonal. 200 | 201 | Write a program that takes the position of the queen and position of the opponent piece on an empty chessboard and 202 | determine if the queen may attack the piece. 203 | 204 | Input 205 | ------ 206 | The first line of the input consists of an integer- cord_x1, representing the x coordinate of the queen; 207 | 208 | The second line of the input consists of an integer- cord_y1,representing the y coordinate of the queen; 209 | 210 | The third line of the input consists of an integer- cord_x2, representing the x coordinate of the opponent piece; 211 | 212 | The fourth line of the input consists of an integer- cord_y2,representing the y coordinate of the opponent 213 | piece. 214 | 215 | Output 216 | ------- 217 | Print a string "Yes" the queen can attack the opponent piece. Otherwise, print 218 | "No." 219 | 220 | 221 | Examples 222 | --------- 223 | Example1: 224 | 225 | Input: 226 | 4 227 | 5 228 | 6 229 | 7 230 | 231 | Output: 232 | Yes 233 | 234 | Explanation: 235 | ------------ 236 | When the queen is located at position (4,5) and the opponent piece is located at position (6,7), the Queen may attack 237 | the piece in a diagonal attack 238 | 239 | 240 | Example 2: 241 | input: 242 | 1 243 | 1 244 | 3 245 | 2 246 | 247 | output: 248 | No 249 | 250 | Explanation: 251 | ------------ 252 | When the queen is located at position (1,1) pieces and the opponent piece is located at position (3,2), the queen may 253 | not attack the piece because it is not located in the same row, same column , or same diagonally. -------------------------------------------------------------------------------- /RealPage/Old Questions/realpage questions.txt: -------------------------------------------------------------------------------- 1 | Task 1 2 | ------ 3 | 4 | Problem 1: Smallest integer with double the digit sum 5 | ------------------------------------------------------ 6 | Write a function 7 | 8 | class Solution { public int solution(int N);} 9 | 10 | that, given an integer N, returns the smallest integer greater than N where the sum of its digits 11 | is twice as big as the sum of the digits of N. 12 | 13 | Examples: 14 | --------- 15 | 1.Given N=14, the function should return 19. The sum of digits of 19 (1+9=10) is twice as big as 16 | the sum of digits of 14 (1+4=5). 17 | 18 | 2.Given N=10, the function should return 11. 19 | 20 | 3.Given N=99, the function should return 9999. 21 | 22 | Assumption: 23 | ----------- 24 | N is an integer within the range [1..500]. 25 | 26 | In your solution, focus on correctness; the performance of the solution will not be the focus of 27 | the assessment. 28 | 29 | Problem 2: Longest string with unique letters 30 | --------------------------------------------- 31 | Concatenation is an operation that joins strings.For example, the concatenation of strings "smart" 32 | and "phone" is "smartphone". 33 | 34 | Concatenation can be expanded to more than two strings; for example,Concatenation "co","dil" and 35 | "ity" results in "codility". 36 | 37 | Given an array A consisting of strings, your function should calculate the length of the longest 38 | string S such that. 39 | 40 | *S is a concatenation of some of the strings from A. 41 | *Every letter in S is different. 42 | 43 | Write a function: 44 | class Solution { public int solution(String[] A);} 45 | 46 | that given an array A consisting of N strings, calculates the length of the longest string S 47 | fulfilling the conditions above.If no such string exists, your function should return 0. 48 | 49 | Examples: 50 | --------- 51 | 1.Given A = ['co', 'dil', 'ity'], your function should return 5. A possible resulting string S 52 | could be "codil", "dilco", "coity" or "ityco". 53 | 54 | 2.Given A = ['abc', 'yyy', 'def', 'csv'], your function should return 6. A possible resulting 55 | string S could be "abcdef", "defabc", "defcsv" or "csvdef". 56 | 57 | 3.Given A = ['potato', 'kayak', 'banana', 'racecar'], your function should return 0. It is 58 | impossible to choose any of these strings as each of them contains repeating letters. 59 | 60 | 4.Given A = ['eva', 'jqw', 'tyn', 'jan'], your function should return 9. One of the possible 61 | strings of this length is "evajqwtyn". 62 | 63 | Assumptions: 64 | ------------ 65 | *N is an integer within the range [1..8]. 66 | *Each string in A consists of lowercase English letters. 67 | *The sum of lengths of strings in A does not exceed 100. 68 | 69 | In your solution, focus on correctness; the performance of your solution will not be the focus of 70 | the assessment. 71 | 72 | Problem 3: Filling glasses with water 73 | -------------------------------------- 74 | 75 | There are N empty glasses with a capacity of 1, 2, ..., N liters (there is exactly one glass of each unique capacity). You want to pour exactly K liters of water into the glasses. Each glass may be either full or empty (a glass cannot be partially filled). What is the minimum number of glasses that you need to contain K liters of water? 76 | 77 | Write a function: 78 | 79 | int solution(int N, int K); 80 | 81 | that, given two integers N and K, returns the minimum number of glasses that are needed to contain exactly K liters of water. If it is not possible to pour exactly K liters of water into glasses, then the function should return -1. 82 | 83 | Examples: 84 | ---------- 85 | 1.Given N=5 and K=8, the function should return 2. There are five glasses with capacity 1, 2, 3, 4 and 5. You can use two glasses with capacity 3 and 5 to hold 8 liters of water. 86 | 87 | 2.Given N=4 and K=10, the function should return 4. You must use all the glasses to contain 10 liters of water. 88 | 89 | 3.Given N=1 and K=2, the function should return -1. There is only one glass with capacity 1, so you cannot pour 2 liters of water. 90 | 91 | 4.Given N=10 and K=5, the function should return 1. You can use the glass with capacity 5. 92 | 93 | Assumptions: 94 | ------------ 95 | N is an integer within the range [1..1,000,000]. 96 | 97 | K is an integer within the range [1..1,000,000]. 98 | 99 | Task 2 100 | ------- 101 | Write a function solution that, given an integer N, returns the maximum possible value obtainable 102 | by deleting one '5' digit from the decimal representation of N. It is guaranteed that N will 103 | contain at least one '5' digit. 104 | 105 | Examples: 106 | --------- 107 | Given N=15958, the function should return 1958. 108 | Given N=-5859, the function should return -589. 109 | Given N=-5000, the function should return 0. After deleting the '5', the only digits in the number 110 | are zeroes, so its value is 0. 111 | 112 | Assumptions: 113 | ------------ 114 | 1.N is an integer within the range -999,995 to 999,995. 115 | 2.N contains at least one '5' digit in its decimal representation. 116 | N consists of at least two digits in its decimal representation. 117 | 118 | In your solution, focus on correctness; the performance of your solution will not be the focus of 119 | the assessment. 120 | 121 | Task 3 122 | ------ 123 | For each of the following questions choose only one correct answer. 124 | 125 | 1. What is a garbage collector pause? 126 | 127 | A: It is the period when an application is stopped to clean up its unused memory 128 | B: It is a way to temporarily disable garbage collection. 129 | C: It happens when the garbage collector no longer has an opportunity to run. 130 | 131 | 2. Is the following statement valid in Java? float x = 3.14; 132 | 133 | A: No, because 3.14 is a double literal 134 | B: Yes. 135 | C: Yes, but the compiler will emit a warning. 136 | 137 | 3. Is it good practice to make all methods public? 138 | 139 | A: Yes, it allows you to test all of your methods. 140 | 141 | 4. Can you iterate over elements stored in a Java HashMap? 142 | 143 | A: No, you cannot. 144 | B: Yes, but the order of the elements is undefined. 145 | C: Yes, and the elements are always sorted by the defined keys. 146 | 147 | 5. What is the best way to validate a telephone number in your application? 148 | 149 | A: Write your own parser. 150 | B: Use a regular expression and check if the result matches your string. 151 | C: Parse it as an integer. 152 | 153 | 6. What would be a good way of describing streams in Java 8? 154 | 155 | A: Streams are processing patterns that work on your data. 156 | B: Streams are data structures that store incoming data. 157 | C: Streams are APIs for streaming data in your web application. 158 | 159 | 7. What is the time complexity of appending an element to an ArrayList? 160 | 161 | A: Always O(1). 162 | B: Always O(n). 163 | C: Amortized O(1). 164 | 165 | 8. What is the main purpose of buffered Input/Output streams? 166 | 167 | A: To increase performance, as most I/O operations are done in a block. 168 | B: To be able to read/write the same file from many threads at once. 169 | C: It is a security measure against buffer overflows and denial-of-service attacks. 170 | 171 | 9. What is the visibility of a class without an access modifier? 172 | 173 | class Sample{ 174 | ..... 175 | } 176 | 177 | A: It is the same as public. 178 | B: It is public if it has the same name as a source file, otherwise it is the same as private. 179 | C: It is visible within the same package. 180 | 181 | 10. What is the JAR file format? 182 | 183 | A: It is a Java bytecode format. 184 | B: It is a platform-specific package type that allows applications to be launched. 185 | C: It is a package built on the ZIP format, aggregating Java class files, metadata and resources. 186 | 187 | 11. What is an anonymous class? 188 | 189 | A: It is a private class inside another class. It can only be used within that class. 190 | B: It is a way of writing more reusable code by allowing a class to implement an interface. 191 | C: It is a way to declare a class and instantiate an object at the same time. 192 | 193 | 12.What is a lambda expression? 194 | 195 | A: It is a way of calling short Python snippets from Java. 196 | B: It is a shorthand way of coding to avoid boiler plate code. 197 | C: It is a new method in Hadoop that allows you to execute large sets of statements without tinkering with the exact filtering order of passed objects. 198 | 199 | 13.What class modifier do you use when a given class should not be inherited? 200 | 201 | A: final. 202 | B: static. 203 | C: private. 204 | 205 | 14.Can memory leak in Java? 206 | 207 | A: No, the garbage collector prevents it. 208 | B: Yes, you can still keep references to objects that you do not need anymore, and they will accumulate in memory. 209 | C: It depends on the garbage collector algorithm. 210 | 211 | 212 | 213 | 15.How can you break out of a for loop inside a nested loop? 214 | 215 | for(int i=0;i<10;i++){ 216 | while(j<100){ 217 | ... 218 | //break; 219 | ... 220 | } 221 | } 222 | 223 | A:It is not possible with break.instead,you need to refactor your code (eg. use a separate method) 224 | B: Assign a label,"outerLoop:for(..."and then break outerLoop; 225 | C:Use return instead. 226 | 227 | 16.Can you modify the object set? 228 | 229 | final Set set =new HashSet<>(Arrays.asList("first","second")); 230 | 231 | A: The set is immutable; it cannot be modified in any way. 232 | B: You cannot add or remove elements to or from a set ,but you can reassign a different object as the set variable. 233 | C:You can add and remove elements to and from a set. but you cannot reassign a different object to the set. 234 | 235 | 236 | 17.Which of following sentences in not true about Java Streams (8)? 237 | 238 | A: One strea can be reused and visited many times 239 | B: The streams can be of infinite size and because of laziness, they can short circuit a lot of operations 240 | C:They can be paralellized easily 241 | 242 | 18.What would the following code output? 243 | System.out.println(String.format("Id = %08.2f", 423.147)); 244 | 245 | A: Id = 00000423.15. 246 | B: It will throw an exception. 247 | C: Id = 00423.15. 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /DBS/DBSBootcamp/Day-01/quiz1.txt: -------------------------------------------------------------------------------- 1 | Question 1: 2 | What is the base case for the recursive height calculation of a binary tree? 3 | a. When root is not NULL 4 | b. When root has one child 5 | c. When root is NULL 6 | d. When root has two children 7 | Answer: c. When root is NULL 8 | 9 | Question 2: 10 | What will be the output of the following program? 11 | public class Test { 12 | public static void main(String[] args) { 13 | int a = 5; 14 | int b = 10; 15 | System.out.println(a++ * --b); 16 | } 17 | } 18 | a. 40 19 | b. 55 20 | c. 50 21 | d. 45 22 | Answer: d. 45 23 | 24 | Question 3: 25 | What will be the output of the following program? 26 | class Test { 27 | public static void main(String[] args) { 28 | int x = 5; 29 | x += x++ + ++x; 30 | System.out.println(x); 31 | } 32 | } 33 | a. 16 34 | b. 18 35 | c. 17 36 | d. 19 37 | Answer: c. 17 (Very important x+=y is treated as x = x + y , eventhough x get's changed during the process the original value of x is still used when computing x = x + y => x = 5 + y in this case). 38 | 39 | Question 4: 40 | What happens when this code is executed? 41 | class Test { 42 | public static void main(String[] args) { 43 | int x = 5; 44 | int y = ++x + x++ + --x; 45 | System.out.println(y); 46 | } 47 | } 48 | a. 17 49 | b. 16 50 | c. 15 51 | d. 18 52 | Answer: d. 18 53 | 54 | Question 5: 55 | What does this function do? 56 | Function func(Node root): 57 | if root is NULL: 58 | return 0 59 | return 1 + func(root.left) + func(root.right) 60 | a. Counts the number of nodes in the tree 61 | b. Finds the diameter of the tree 62 | c. Finds the height of the tree 63 | d. Counts the number of leaves 64 | Answer: a. Counts the number of nodes in the tree 65 | 66 | Question 6: 67 | What does the following pseudo-code do? 68 | Function fun(Node head): 69 | prev = NULL 70 | curr = head 71 | while curr is not NULL: 72 | next = curr.next 73 | curr.next = prev 74 | prev = curr 75 | curr = next 76 | return prev 77 | a. Finds the middle element 78 | b. Deletes the linked list 79 | c. Reverses the linked list 80 | d. Sorts the linked list 81 | Answer: c. Reverses the linked list 82 | 83 | Question 7: 84 | What happens when this code is executed? 85 | int num = 10; 86 | System.out.println((num > 5) ? (num < 20 ? "Within Range" : "Out of Range") : "Too Low"); 87 | a. Within Range 88 | b. Too Low 89 | c. Out of Range 90 | d. Compilation Error 91 | Answer: a. Within Range 92 | 93 | Question 8: 94 | What will be printed? 95 | String s1 = "OCA"; 96 | String s2 = "O" + "C" + "A"; 97 | System.out.println(s1 == s2); 98 | a. false 99 | b. true 100 | c. Compilation Error 101 | d. Runtime Exception 102 | Answer: b. true 103 | 104 | Question 9: 105 | What does this function do? 106 | Function func(Node head): 107 | if head is NULL: 108 | return NULL 109 | return head.next 110 | a. Does nothing 111 | b. Deletes all nodes 112 | c. Deletes the last node 113 | d. Deletes the first node of the linked list 114 | Answer: d. Deletes the first node of the linked list 115 | 116 | Question 10: 117 | What happens when the following code is executed? 118 | for (int i = 0; i < 5; i++) { 119 | System.out.print(i + " "); 120 | } 121 | System.out.println("\n" + i); 122 | a. Runtime Error 123 | b. 0 1 2 3 4 5 124 | c. None of the above 125 | d. Compilation Error 126 | Answer: d. Compilation Error 127 | 128 | Question 11: 129 | What will be the output of the following program? 130 | System.out.println(10 + 20 + "Java" + 10 + 20); 131 | a. 30Java1020 132 | b. Compilation Error 133 | c. 30Java30 134 | d. Java30 135 | Answer: a. 30Java1020 136 | 137 | Question 12: 138 | What does this function implement? 139 | Function func(Queue Q, int val): 140 | if Q.rear == MAX_SIZE: 141 | return "Queue Overflow" 142 | Q.rear = Q.rear + 1 143 | Q[Q.rear] = val 144 | a. Dequeue operation 145 | b. Enqueue operation in a queue 146 | c. Push operation in a stack 147 | d. Insert at the beginning of a linked list 148 | Answer: b. Enqueue operation in a queue 149 | 150 | Question 13: 151 | What happens when the following function is executed on an empty queue? 152 | 153 | Function func(Queue Q): 154 | if Q.front == Q.rear: 155 | return "Queue Underflow" 156 | Q.front = Q.front + 1 157 | return Q[Q.front] 158 | 159 | a. The queue becomes empty 160 | b. The queue becomes full 161 | c. An element is removed from the queue 162 | d. "Queue Underflow" is returned 163 | Answer: d. "Queue Underflow" is returned 164 | 165 | Question 14: 166 | Which data structure is implemented by this function? 167 | Function func(Node S, int val): 168 | if S.top == MAX_SIZE: 169 | return "Overflow" 170 | S.top = S.top + 1 171 | S[S.top] = val 172 | a. Heap 173 | b. Deque 174 | c. Stack 175 | d. Queue 176 | Answer: c. Stack 177 | 178 | Question 15: 179 | What happens when the following code is executed? 180 | String s1 = "hello"; 181 | String s2 = new String("hello"); 182 | System.out.println(s1 == s2); 183 | System.out.println(s1.equals(s2)); 184 | a. false false 185 | b. false true 186 | c. true false 187 | d. true true 188 | Answer: b. false true 189 | 190 | Question 16: 191 | What traversal does this function perform? 192 | Function traverse(Node root): 193 | if root is NULL: 194 | return 195 | traverse(root.left) 196 | print(root.data) 197 | traverse(root.right) 198 | a. Level-order 199 | b. Inorder 200 | c. Preorder 201 | d. Postorder 202 | Answer: b. Inorder 203 | 204 | Question 17: 205 | What will be the output of the following program? 206 | Integer a = 10; 207 | Integer b = 10; 208 | Integer c = 200; 209 | Integer d = 200; 210 | System.out.println(a == b); 211 | System.out.println(c == d); 212 | a. false false 213 | b. true false 214 | c. true true 215 | d. false true 216 | Answer: b. true false (Java caches Integer objects in the range -128 to 127, so == may return true for small values — similar caching applies to Byte, Short, Character (0–127), and Boolean.) 217 | 218 | Question 18: 219 | What is the output of the following pseudo-code? 220 | Queue Q = new Queue() 221 | enqueue(Q, 5) 222 | enqueue(Q, 10) 223 | enqueue(Q, 15) 224 | dequeue(Q) 225 | print(front(Q)) 226 | a. 10 227 | b. 15 228 | c. 5 229 | d. Error 230 | Answer: a. 10 231 | 232 | Question 19: 233 | What will be printed when the following pseudo-code runs? 234 | 235 | Function func(Node head): 236 | if head is NULL: 237 | return 238 | print(head.data) 239 | func(head.next) 240 | 241 | For a linked list 1 -> 2 -> 3 -> NULL 242 | a. NULL 243 | b. 1 2 3 244 | c. 3 2 1 245 | d. Infinite loop 246 | Answer: b. 1 2 3 247 | 248 | Question 20: 249 | What will be the output of the following pseudo-code? 250 | 251 | struct Node { 252 | int data; 253 | Node next; 254 | } 255 | 256 | Function fun(Node head): 257 | count = 0 258 | while head is not NULL: 259 | count = count + 1 260 | head = head.next 261 | return count 262 | 263 | a. 4 264 | b. 5 265 | c. 6 266 | d. NULL 267 | Answer: a. 4 268 | 269 | Question 21: 270 | What will be the output of the following program? 271 | String str1 = "Java"; 272 | String str2 = "Java"; 273 | String str3 = new String("Java"); 274 | System.out.println(str1 == str2); 275 | System.out.println(str1 == str3); 276 | a. false false 277 | b. true true 278 | c. false true 279 | d. true false 280 | Answer: d. true false 281 | 282 | Question 22: 283 | What does this function return? 284 | 285 | Function func(Node head): 286 | slow = head 287 | fast = head 288 | while fast is not NULL and fast.next is not NULL: 289 | slow = slow.next 290 | fast = fast.next.next 291 | return slow.data 292 | a. The middle node 293 | b. The first node 294 | c. The last node 295 | d. The head node 296 | Answer: a. The middle node 297 | 298 | Question 23: 299 | What does the following function return? 300 | 301 | Function func(Node root): 302 | if root is NULL: 303 | return MIN_VALUE 304 | return max(root.data, func(root.left), func(root.right)) 305 | 306 | a. Minimum value in the tree 307 | b. Sum of all values 308 | c. Maximum value in the tree 309 | d. Number of nodes 310 | Answer: c. Maximum value in the tree 311 | 312 | Question 24: 313 | What will happen when the following code runs? 314 | 315 | int[] arr = new int[5]; 316 | System.out.println(arr[5]); 317 | 318 | a. NullPointerException 319 | b. Compilation Error 320 | c. 0 321 | d. ArrayIndexOutOfBoundsException 322 | Answer: d. ArrayIndexOutOfBoundsException 323 | 324 | Question 25: 325 | What does the following function implement? 326 | 327 | Function func(Deque D, int val): 328 | if D.front == 0: 329 | return "Overflow" 330 | D.front = D.front - 1 331 | D[D.front] = val 332 | 333 | a. Insert in a priority queue 334 | b. Insert at the front in a deque 335 | c. Insert in a stack 336 | d. Insert at the rear in a queue 337 | Answer: b. Insert at the front in a deque 338 | 339 | Question 26: 340 | What happens when this code is executed? 341 | class Parent { 342 | static void show() { 343 | System.out.println("Parent"); 344 | } 345 | } 346 | class Child extends Parent { 347 | static void show() { 348 | System.out.println("Child"); 349 | } 350 | public static void main(String[] args) { 351 | Parent obj = new Child(); 352 | obj.show(); 353 | } 354 | } 355 | a. Runtime Exception 356 | b. Child 357 | c. Parent 358 | d. Compilation Error 359 | Answer: c. Parent (obj is of type Parent, so Parent.show() is called.) 360 | 361 | Question 27: 362 | 363 | What is the output of the following program? 364 | 365 | class A { 366 | static void display() { 367 | System.out.println("Static A"); 368 | } 369 | } 370 | class B extends A { 371 | static void display() { 372 | System.out.println("Static B"); 373 | } 374 | } 375 | public class Test { 376 | public static void main(String[] args) { 377 | A obj = new B(); 378 | obj.display(); 379 | } 380 | } 381 | a. Compilation Error 382 | b. Runtime Exception 383 | c. Static A 384 | d. Static B 385 | Answer: c. Static A 386 | 387 | Question 28: 388 | 389 | What will be the output of the following code? 390 | int x = 10; 391 | int y = 5; 392 | System.out.println(x > y ? "Greater" : x == y ? "Equal" : "Smaller"); 393 | 394 | a. Greater 395 | b. Compilation Error 396 | c. Equal 397 | d. Smaller 398 | Answer: a. Greater 399 | 400 | Question 29: 401 | 402 | What is the output of the following program? 403 | int x = 5; 404 | System.out.println(x > 2 || x++ < 10); 405 | System.out.println(x); 406 | 407 | a. false 5 408 | b. true 5 409 | c. true 6 410 | d. false 6 411 | Answer: b. true 5 412 | 413 | Question 30: 414 | 415 | What is the output of this pseudo-code if executed on a binary tree? 416 | Function func(Node root): 417 | if root is NULL: 418 | return 0 419 | return root.data + func(root.left) + func(root.right) 420 | 421 | a. Height of the tree 422 | b. Sum of all node values 423 | c. Number of nodes 424 | d. Maximum node value 425 | Answer: b. Sum of all node values 426 | -------------------------------------------------------------------------------- /Verisk/Round 1/Aptitude/logical.md: -------------------------------------------------------------------------------- 1 | ## Logical Reasoning 2 | 3 | #### 1. A person starts at point A and moves 16 km west to reach point B. From point B, they turn right and travel 5 km to reach point C. Next, they move 16 km east from point C to reach point D. Finally, they turn left from point D and travel 5 km to reach point E. What is the straight-line distance between point E and point A? 4 | 5 | Answer: 6 | Let’s fix the directions properly: 7 | Let point A = (0, 0) 8 | A → B: 16 km west → B = (-16, 0) 9 | B → C: turn right (i.e., north) → C = (-16, 5) 10 | C → D: 16 km east → D = (0, 5) 11 | D → E: turn left (i.e., north again) → E = (0, 10) 12 | **The straight-line distance between point E and point A is 10 km.** 13 | 14 | #### 2. Count the number of times the lowercase letter ‘j’ appears in the following string: 15 | 16 | "jljjlkljjjlkljkjljjjjkjljjjjjjjjljkllj" 17 | 18 | A) 19 19 | B) 20 20 | C) 21 21 | D) 22 22 | 23 | Answer: 24 | **C) 21** 25 | #### 3. FREE -> FTEG , LEAD -> ? 26 | 27 | Let's analyze the pattern from FREE to FTEG: 28 | 29 | >F remains F (no change) 30 | R becomes T (R + 2 letters in the alphabet) 31 | E remains E (no change) 32 | E becomes G (E + 2 letters in the alphabet) 33 | 34 | Applying this same pattern to LEAD: 35 | 36 | >L remains L 37 | E becomes G (E + 2 letters in the alphabet) 38 | A remains 39 | D becomes F (D + 2 letters in the alphabet) 40 | 41 | **Therefore, LEAD transforms into LGAF.** 42 | 43 | #### 4.Garland Arrangement Puzzle 44 | 45 | A unique garland is made up of 7 different colored flowers. Six of these colors are placed at equal intervals around the circumference of a circle. The seventh color, Yellow, isn't on the circumference itself but is hung as a decoration between two neighboring flowers on the circumference. 46 | 47 | Use the following clues to determine the arrangement of the flowers: 48 | 49 | - Orange is three places to the right of Red, and Red is placed one place to the right of Indigo. 50 | - Violet forms a 90-degree angle with Yellow and a 120-degree angle with Blue (angles are measured from the center of the circle to the flowers' positions). 51 | - Blue is opposite to Green and to the left of Yellow. 52 | 53 | Based on this information, answer the following questions: 54 | 55 | 1. What is the angle (in degrees) between Yellow and Indigo? 56 | 2. Which flowers are located between Yellow and Green when moving in an anti-clockwise direction? 57 | 58 | Solution 59 | 60 | Let's deduce the arrangement step-by-step. We'll label the six positions on the circumference P1 through P6, moving clockwise, with each position 60∘ apart (0∘,60∘,120∘,180∘,240∘,300∘). The colors on the circumference are Red, Orange, Green, Blue, Indigo, and Violet. Yellow is positioned in an arc between two of these. 61 | 62 | ##### Placing Indigo, Red, and Orange (Clue 1): 63 | 64 | Let's place Indigo (I) at P1 (0∘). 65 | Red (R) is one place to the right (clockwise) of Indigo, so Red is at P2 (60∘). 66 | Orange (O) is three places to the right (clockwise) of Red (P2). Counting three places clockwise: P3 (1st), P4 (2nd), P5 (3rd). So, Orange is at P5 (240∘). 67 | *Current known positions*: 68 | 69 | - P1: Indigo 70 | 71 | - P2: Red 72 | 73 | - P5: Orange 74 | 75 | - Remaining positions for Green, Blue,Violet: P3, P4, P6. 76 | 77 | ##### Placing Blue and Green (Clue 3, part 1): 78 | 79 | - Blue (B) is opposite to Green (G). This means they are three positions apart. 80 | 81 | - Considering the remaining positions (P3, P4, P6): 82 | 83 | - If Blue is at P3, Green would be at P6 (3 positions apart). 84 | 85 | - If Blue is at P4, Green would be at P1, which is already Indigo, so this isn't possible. 86 | 87 | - If Blue is at P6, Green would be at P3. 88 | 89 | ##### Placing Violet and Verifying Blue/Green (Clue 2, part 1): 90 | - Violet (V) forms a 120∘ angle with Blue. This means Violet and Blue are two positions apart on the circumference. 91 | 92 | - Let's test the two possibilities for Blue and Green: 93 | 94 | - Scenario A: Blue at P3, Green at P6. 95 | 96 | - Violet would then be at P4. 97 | 98 | - Angle between Violet (P4 at 180∘) and Blue (P3 at 120∘) is 180∘−120∘=60∘. This contradicts the 120∘ requirement. So, Scenario A is incorrect. 99 | 100 | - Scenario B: Blue at P6, Green at P3. 101 | 102 | - Violet would then be at P4. 103 | 104 | - Angle between Violet (P4 at 180∘) and Blue (P6 at 300∘) is ∣180∘−300∘∣=120∘. This matches the clue! 105 | 106 | ##### Confirmed arrangement: 107 | 108 | - P1: Indigo 109 | 110 | - P2: Red 111 | 112 | - P3: Green 113 | 114 | - P4: Violet 115 | 116 | - P5: Orange 117 | 118 | - P6: Blue 119 | 120 | ##### Placing Yellow (Clue 3, part 2 & initial setup): 121 | 122 | - "Blue is left of Yellow" and "Yellow is hang as decoration at one end between neighbour flowers." 123 | 124 | - Since Blue is at P6, for Yellow to be to its right (and Blue to its left), Yellow must be located between Blue (P6) and Indigo (P1). This fits the description of Yellow being between "neighbour flowers" (Blue and Indigo). 125 | 126 | 127 | ##### The final arrangement of flowers (clockwise): 128 | - Indigo (P1) - Red (P2) - Green (P3) - Violet (P4) - Orange (P5) - Blue (P6). 129 | - Yellow is located in the arc between Blue (P6) and Indigo (P1). 130 | 131 | ***Note on Clue 2**: "Violet form 90∘ with Yellow". Violet is at P4 (180∘). Yellow's conceptual position (midpoint of P6 and P1) is 330∘. The angle between 180∘ and 330∘ is 150∘. Given that all other clues are consistent, this particular 90∘ might refer to a non-standard measurement or be a slight inconsistency in the puzzle's design. We proceed with the arrangement that satisfies all other, more precise angular and positional clues.* 132 | 133 | Answers to the Questions: 134 | 135 | 1. **Angle between Yellow and Indigo**: 136 | 137 | - Indigo is at P1 (0∘). 138 | 139 | - Yellow is located in the arc between P6 (300∘) and P1 (0∘). Its conceptual angular position (midpoint) is (300∘+360∘)/2=330∘. 140 | 141 | - The angle between Yellow (330∘) and Indigo (0∘ or 360∘) is 360∘−330∘=30∘. 142 | 143 | 2. **Flowers between Yellow and Green in anti-clockwise direction**: 144 | 145 | - Yellow is between P6 (Blue) and P1 (Indigo). 146 | 147 | - Green is at P3. 148 | 149 | - Moving anti-clockwise from Yellow's position (between P6 and P1) towards Green (P3), we pass through: 150 | 151 | - Blue (at P6) 152 | 153 | - Orange (at P5) 154 | 155 | - Violet (at P4) 156 | 157 | - Therefore, the flowers between Yellow and Green in the anti-clockwise direction are Blue, Orange, and Violet. 158 | 159 | #### 6. Identify the pattern in the following number sequence and find the missing term: 160 | 161 | **39, 24, 19, 12, ?, 4** 162 | 163 | Answer: 164 | 165 | To find the missing number, we need to analyze the differences between consecutive terms in the given sequence: 166 | 167 | Calculate the initial differences: 168 | 169 | 39−24=15 170 | 24−19=5 171 | 19−12=7 172 | 173 | **The sequence of subtractions observed so far is: 15, 5, 7.** 174 | 175 | Analyze the pattern in the sequence of subtractions: 176 | Let's look at the differences between these subtraction values: 177 | 178 | From 15 to 5: 5 − 15 = −10 179 | From 5 to 7: 7 − 5 = 2 180 | 181 | While the first two changes are different, a common pattern in such sequences is that the 'difference of differences' eventually becomes consistent. Let's assume the next change in the subtraction sequence continues with a consistent pattern, specifically by alternating or following a simple series. 182 | 183 | If we assume the pattern for the changes in subtractions becomes +2, -2, -2... (after the initial -10): 184 | 185 | The next subtraction value after 7 would be 7−2=5. 186 | The next subtraction value after 5 would be 5−2=3. 187 | **So, the complete sequence of subtractions is: 15, 5, 7, 5, 3.** 188 | 189 | ##### Apply the pattern to find the missing number: 190 | 191 | Starting from 12, we apply the next subtraction in our derived sequence (which is 5): 192 | 12−5=7 193 | 194 | Verify the final step: 195 | 196 | - Now, apply the last subtraction in our sequence (which is 3) to the number we found: 197 | 7−3=4 198 | 199 | - This matches the last number in the given sequence, confirming our pattern. 200 | 201 | - Therefore, the completed sequence is: 39, 24, 19, 12, 7, 4. 202 | 203 | The missing number is 7. 204 | #### 7. Question: 205 | 206 | Statement: 207 | A > B ≥ C 208 | C < D ≤ E 209 | 210 | Conclusions: 211 | I. D > B 212 | II. A = E 213 | 214 | Options (Typical in exams): 215 | a) Only conclusion I is true. 216 | b) Only conclusion II is true. 217 | c) Either conclusion I or II is true. 218 | d) Neither conclusion I nor II is true. 219 | e) Both conclusions I and II are true. 220 | 221 | Answer: 222 | 223 | Let's analyze the given statement and each conclusion: 224 | 225 | **Statement Breakdown**: 226 | 227 | - A > B ≥ C: This means A is strictly greater than B, and B is greater than or equal to C. 228 | 229 | - C < D ≤ E: This means C is strictly less than D, and D is less than or equal to E. 230 | 231 | *We can combine these two parts through the common element 'C':* 232 | **A > B ≥ C < D ≤ E** 233 | 234 | **Analyzing the Conclusions:** 235 | 1. Conclusion I: D > B 236 | 237 | - From the combined statement, we have B ≥ C and C < D. 238 | 239 | - Combining these, we get B ≥ C < D. 240 | 241 | - The relationship between B and D is: 242 | 243 | 1. If B = C, then C < D implies B < D. 244 | 245 | 2. If B > C, then C < D means B's relation to D is not definitively established from this specific path (B > C < D could mean B > D, B < D, or B = D). 246 | 247 | - Because we have an "open mouth" (change in direction of inequality sign: ≥ followed by <) between B and D (B ≥ C < D), a definite relationship (greater than, less than, or equal to) between B and D cannot be established. 248 | 249 | - We cannot conclusively say that D > B. It's possible, but not certain. For instance, if B=5, C=5, D=6, then D>B. But if B=5, C=4, D=6, then D>B. If B=5, C=4, D=4, this is not possible as D>C. 250 | 251 | - Consider specific values: 252 | 253 | - Let C = 5. 254 | 255 | - Then B could be 5 or 6 (e.g., B=6). 256 | 257 | - D must be greater than C, so D could be 6 (D > C). 258 | 259 | - If B=6 and D=6, then D is not greater than B. (This violates D > B) 260 | 261 | - Therefore, Conclusion I is False (or more accurately, "Cannot be determined" / "Not necessarily true"). 262 | 263 | 2. Conclusion II: A = E 264 | 265 | - From the combined statement: A > B ≥ C < D ≤ E 266 | 267 | - There is a clear break (change in inequality direction: ≥ followed by <) in the path from A to E. 268 | 269 | - Because there are opposing signs (≥ and <) in the chain connecting A and E, no direct or definite relationship (greater than, less than, or equal to) can be established between A and E. 270 | 271 | - We cannot conclusively say that A = E. 272 | 273 | - Therefore, Conclusion II is False (or "Cannot be determined" / "Not necessarily true"). 274 | 275 | Final Decision: 276 | 277 | Since neither conclusion I nor conclusion II can be definitively proven true from the given statement, the correct option is: 278 | 279 | **d) Neither conclusion I nor II is true.** 280 | 281 | *Flow chart and diagram based questions are also asked in this section in exam* 282 | > **_NOTE:_** Answer are AI generated please double check the answers. --------------------------------------------------------------------------------