• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Pro Programming

Professional way of Programming: Learn C, C++, Java, Python, Dot Net, Android the professional way

  • Home
  • C MCQs
  • C/C++ Programs
  • Java Programs
  • C#
  • Python
  • MySQL
  • Topics
    • Arrays
    • Strings
    • Link Lists
    • Trees
    • Shapes
  • Projects
  • Articles
  • Games
You are here: Home / Archives for 0 - 1 Knapsack Problem

0 - 1 Knapsack Problem

Co-ordinate Compression Multiple Choice Questions and Answers (MCQs)

Leave a Comment


This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Co-ordinate Compression”.

1. What is co-ordinate compression?
a) process of reassigning co-ordinates to remove gaps
b) inserting gaps in a co-ordinate system
c) removing redundant co-ordinates
d) adding extra gaps
View Answer

Answer: a
Explanation: Co-ordinate compression is the process of reassigning co-ordinates in order to remove gaps. This helps in improving efficiency of a solution.

2. What is the need for co-ordinate compression?
a) for improving time complexity
b) for improving space complexity
c) for improving both time and space complexity
d) for making code simpler
View Answer

Answer: c
Explanation:Co-ordinate compression is the process of reassigning co-ordinates in order to remove gaps. This helps in improving both time and space complexity of a solution.

3. What is the output for the following code?

#include <bits/stdc++.h> 
using namespace std;  
void convert(int a[], int n) 
{ 	
	vector <pair<int, int> > vec;	
	for (int i = 0; i < n; i++) 
		vec.push_back(make_pair(a[i], i)); 
	sort(vec.begin(), vec.end()); 	
	for (int i=0; i<n; i++) 
		a[vec[i].second] = i; 
} 
void printArr(int a[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << a[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10,8,2,5,7}; 
	int n = sizeof(arr)/sizeof(arr[0]);  
	convert(arr , n); 
   	printArr(arr, n); 
	return 0; 
}

a) 4 3 0 1 2
b) 1 2 3 4 5
c) 5 4 1 2 3
d) 0 1 2 3 4
View Answer

Answer: a
Explanation: The given code converts the elements of the input array. They are replaced with their respective position number in the sorted array.

4. What will be the time complexity of given code?

#include <bits/stdc++.h> 
using namespace std;  
void convert(int a[], int n) 
{ 	
	vector <pair<int, int> > vec; 	
	for (int i = 0; i < n; i++) 
		vec.push_back(make_pair(a[i], i)); 	
	sort(vec.begin(), vec.end()); 	
	for (int i=0; i<n; i++) 
		a[vec[i].second] = i; 
} 
void printArr(int a[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << a[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10,8,2,5,7}; 
	int n = sizeof(arr)/sizeof(arr[0]); 	
	convert(arr , n); 
   	printArr(arr, n); 
	return 0; 
}

a) O(n)
b) O(n log n)
c) O(n2)
d) O(log n)
View Answer

Answer: b
Explanation: The time complexity of the given code will be governed by the time complexity of the sorting algorithm used. As this code uses in built sorting of C++ so it will take O(n log n) time.

5. What is the auxiliary space complexity of the given code?

#include <bits/stdc++.h> 
using namespace std;  
void convert(int a[], int n) 
{ 	
	vector <pair<int, int> > vec; 	
	for (int i = 0; i < n; i++) 
		vec.push_back(make_pair(a[i], i)); 	
	sort(vec.begin(), vec.end()); 
	for (int i=0; i<n; i++) 
		a[vec[i].second] = i; 
} 
void printArr(int a[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << a[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10,8,2,5,7}; 
	int n = sizeof(arr)/sizeof(arr[0]);  
	convert(arr , n); 
   	printArr(arr, n); 
	return 0; 
}

a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
View Answer

Answer: b
Explanation: The given code uses an auxiliary space of O(n). It is used by a vector which pairs each element of the array with their respective index number of the original array.

6. What will be the output of the following code?

#include <bits/stdc++.h> 
using namespace std; 
void convert(int arr[], int n) 
{ 
	int temp[n]; 
	memcpy(temp, arr, n*sizeof(int)); 
	sort(temp, temp + n); 	
        unordered_map<int, int> map; 	
	int sort_index = 0; 
	for (int i = 0; i < n; i++) 
		map[temp[i]] = sort_index++; 	
	for (int i = 0; i < n; i++) 
		arr[i] = map[arr[i]]; 
} 
void printArr(int arr[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << arr[i] << " "; 
} 
int main() 
{ 
	int arr[] = {3,5,2,4}; 
	int n = sizeof(arr)/sizeof(arr[0]); 
	convert(arr , n); 	
	printArr(arr, n); 
	return 0; 
}

a) 0 2 3 4
b) 1 3 0 2
c) 2 4 1 3
d) 1 2 3 4
View Answer

Answer: b
Explanation: The given code converts the elements of input array. They are replaced with their respective position number in the sorted array.

7. What is the time complexity of the following code?

#include <bits/stdc++.h> 
using namespace std; 
void convert(int arr[], int n) 
{ 	
	int temp[n]; 
	memcpy(temp, arr, n*sizeof(int)); 
	sort(temp, temp + n); 	
        unordered_map<int, int> map; 	
	int sort_index = 0; 
	for (int i = 0; i < n; i++) 
		map[temp[i]] = sort_index++; 	
	for (int i = 0; i < n; i++) 
		arr[i] = map[arr[i]]; 
} 
void printArr(int arr[], int n) 
{ 
	for (int i=0; i<n; i++) 
		cout << arr[i] << " "; 
} 
int main() 
{ 
	int arr[] = {10, 20, 15, 12, 11, 50}; 
	int n = sizeof(arr)/sizeof(arr[0]); 
	convert(arr , n); 	
	printArr(arr, n); 
	return 0; 
}

a) O(n)
b) O(1)
c) O(n log n)
d) O(n2)
View Answer

Answer: c
Explanation: The time complexity of the given code will be governed by the time complexity of the sorting algorithm used. As this code uses inbuilt sorting of C++ so it will take O(n log n) time.

8. What will be the auxiliary space complexity of the following code?
a) O(n)
b) O(1)
c) O(log n)
d) O(n log n)
View Answer

Answer: a
Explanation: The given code uses an auxiliary space of O(n). It is used by a vector which pairs each element of the array with their respective index number of the original array.

9. Co-ordinate compression reduces the number of squares in a graph.
a) true
b) false
View Answer

Answer: a
Explanation: The idea behind co-ordinate compression is to reduce the number of squares in a graph by converting them into rectangles of viable size. This reduces the time complexity of traversal.

10. Co-ordinate compression can only be applied in a co-ordinate system problem
a) true
b) false
View Answer

Answer: b
Explanation: Co-ordinate compression technique can be applied where such optimization is suitable. It does not require to co-ordinate system problem only.

Sanfoundry Global Education & Learning Series – Data Structures & Algorithms.

To practice all areas of Data Structures & Algorithms, here is complete set of 1000+ Multiple Choice Questions and Answers.



Source link

Filed Under: c programming Tagged With: •   Array-Recursion-Min-Max, •   Array-Recursion-Search - 1, •   Array-Recursion-Search - 2, •   Assembly Line Scheduling, •   Balanced Partition, •   Best First Search, •   Binary Search Iterative, •   Binary Tree Sort, •   Bipartite Graph, •   Bipartite Graphs Properties, •   Bogosort, •   Boolean Parenthesizations, •   Bottom Up Mergesort, •   Breadth First Search, •   Catalan Number, •   Chan's Algorithm, •   Closest Pair Problem, •   Co-ordinate Compression, •   Coin Change Problem, •   Comb Sort, •   Complete Bipartite Graph, •   Continuous Subarray - 1, •   Continuous Subarray - 2, •   Counting Sort, •   Decimal-Binary Conversion, •   Depth First Search, •   Dice Throw Problem, •   Digits Sum - Recursion, •   Dijkstra's Algorithm, •   Dynamic Programming, •   Edit Distance Problem, •   Eight Queens Problem, •   Euclid's Algorithm, •   Factorial using Recursion, •   Fibonacci Term, •   Fibonacci using Recursion, •   First-in First-out Algorithm, •   Fraction Knapsack Problem, •   GCD & LCM Recursion - 1, •   GCD & LCM Recursion - 2, •   Generating Combinations, •   Generating Partitions, •   Generating Permutations, •   Generating Subsets, •   Gnome Sort, •   Hamiltonian Path Problem, •   Hamming Code, •   Heapsort - 1, •   Heapsort - 2, •   Huffman Code, •   In-place Merge Sort, •   Inclusion Principle, •   Insertion Sort - 1, •   Insertion Sort - 2, •   Introsort, •   Jump Search, •   Kruskal's Algorithm, •   Linear Search Iterative, •   Linear Search Recursive, •   Linkedlist-Length-Recursion, •   Linkedlist-Recursion-Search, •   Lists-Recursion-Min-Max, •   Longest Subsequence, •   LSD Radix Sort, •   Matrix Multiplication, •   Max Bipartite Matching, •   Maximum Flow Problem, •   Minimum Cut, •   Minimum Number of Jumps, •   Minimum Spanning Tree, •   Monoalphabetic Cipher, •   Morse Code - 1, •   Morse Code - 2, •   N Queens Problem, •   Natural No's - Recursion, •   Non-recursive DFS, •   NP Complexity Classes, •   Number Power - Recursion, •   Odd-Even Sort, •   Optimal Page Replacement, •   Palindrome Min Insertions, •   Palindromic Subsequence, •   Pancake Sort, •   Permutation Sort, •   Polyalphabetic Cipher, •   Prim's Algorithm, •   Quick Search Algorithm, •   Quickhull, •   Quickselect, •   Quicksort - 1, •   Quicksort - 2, •   Quicksort - 3, •   Quicksort using Sampling, •   Rabin-Karp Algorithm, •   Rectangle Sum in 2D Matrix, •   Recursive Selection Sort, •   Rod Cutting, •   Selection Sort, •   Shell Sort - 1, •   Shell Sort - 2, •   Sleep Sort, •   Square Root Decomposition, •   Stable Marriage Problem, •   Stack Reversal - Recursion, •   Strassen's Algorithm, •   String Length - Recursion, •   String Reversal - Recursion, •   Timsort, •   Topological Sorting, •   Towers of Hanoi - Recursion, •   Uniform Binary Search, •   Vigenere Cipher, •   Wagner-Fischer Algorithm, 0 - 1 Knapsack Problem, 1000 C Questions & Answers, 1000 Hadoop Questions, 1000 Java Questions & Answers, 1000 Linux Questions & Answers, 1000 PHP Questions & Answers, 1000 Python Questions, About, About Us, Advanced C Training, Aeronautical, Aerospace, Agriculture, Algorithm & Programming Books, All Stream Best Books, All Stream Internships, All Stream Questions & Answers, Backtracking, Bangalore Training, BCA, Bellman–Ford Algorithm, Biotechnology, Bogosort Multiple Choice Questions and Answers (MCQs), Bottom-Up Mergesort Multiple Choice Questions and Answers (MCQs), Bubble Sort, Chemical, Chemical Engineering Books, Chemical Internships, Civil, Civil Engineering Books, Civil Internships, Cloud Computing Questions, Comb Sort Multiple Choice Questions and Answers (MCQs), Computer Science Books, Computer Science Internships, Computer Science Questions, Contact, Contact Us, Copyright, CS, Data Structures & Algorithms II - Questions and Answers, Data Structures & Algorithms Books, Developer Tracks, Developers Track, ECE, EE, EEE, Electrical Engineering Books, Electrical Internships, Electronics Engineering Books, Electronics Internships, Facebook, Fibonacci Search, Floyd Warshall Algorithm, GDB Assignment, here is complete set of 1000+ Multiple Choice Questions and Answers, Home, In-place Merge Sort Multiple Choice Questions and Answers (MCQs), Industrial Engineering Books, Industrial Internships, Instrumentation, Instrumentation Engg Books, Instrumentation Internships, Internship, Introsort Multiple Choice Questions and Answers (MCQs), IS, IT, IT Internships, Jobs, Kadane's Algorithm, Kernel Debugging, Kernel Programming, LinkedIn, Linux Device Drivers, Linux Driver Developer, Linux Fundamentals, Linux Kernel Developer, Linux Network Developer, Linux Threads, Linux-C Debugging, Live Training Photos, Manish, Manish Bhojasia, Marine, Matrix Chain Multiplication, MCA, Mechanical, Mechanical Engineering Books, Mechanical Internships, Mentoring, Mentoring Sessions, Metallurgical Engineering Books, Metallurgy, Mining, Network Programming, Next Page, Next Page - Square Root Decomposition Multiple Choice Questions and Answers (MCQs), Online Training, Operating System Questions and Answers, Permutation Sort Multiple Choice Questions and Answers (MCQs), Prev Page, Prev Page - Quickselect Multiple Choice Questions and Answers (MCQs), Privacy Policy, Programming, Quickhull Multiple Choice Questions and Answers (MCQs), Quickselect Multiple Choice Questions and Answers (MCQs), Quicksort using Random Sampling Multiple Choice Questions and Answers (MCQs), Recursion, SAN Developer, SAN I - Technology, SAN II - Admin, Sitemap, Software Productivity, Square Root Decomposition Multiple Choice Questions and Answers (MCQs), System Programming, Systems Internships, Terms, Test & Rank, Training, Twitter

Square Root Decomposition Multiple Choice Questions and Answers (MCQs)

Leave a Comment


This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Square Root Decomposition”.

1. What is the purpose of using square root decomposition?
a) to reduce the time complexity of a code
b) to increase the space complexity of a code
c) to reduce the space complexity of a code
d) to reduce the space and time complexity of a code
View Answer

Answer: a
Explanation: Square decomposition is mainly used in competitive programming to optimize code. It reduces the time complexity by a factor of √n.

2. By what factor time complexity is reduced when we apply square root decomposition to a code?
a) n
b) √n
c) n2
d) n-1/2
View Answer

Answer: b
Explanation: In square root decomposition a given array is decomposed into small parts each of size √n. This reduces the time complexity of the code by a factor of √n.

3. What will be the worst case time complexity of finding the sum of elements in a given range of (l,r) in an array of size n?
a) O(n)
b) O(l+r)
c) O(l-r)
d) O(r-l)
View Answer

Answer: a
Explanation: For a given array of size n we have to traverse all n elements in the worst case. In such a case l=0, r=n-1 so the time complexity will be O(n).

4. What will be the worst case time complexity of finding the sum of elements in a given range of (l,r) in an array of size n when we use square root optimization?
a) O(n)
b) O(l+r)
c) O(√n)
d) O(r-l)
View Answer

Answer: c
Explanation: When we use square root optimization we decompose the given array into √n chunks each of size √n. So after calculating the sum of each chunk individually, we require to iterate only 3*√n times to calculate the sum in the worst case.

5. Total how many iterations are required to find the sum of elements in a given range of (l,r) in an array of size n when we use square root optimization?
a) √n
b) 2*√n
c) 3*√n
d) n*√n
View Answer

Answer: c
Explanation: After calculating the sum of each chunk individually we require to iterate only 3*√n times to calculate the sum in the worst case. It is because two of the √n factors consider the worst case time complexity of summing elements in the first and last block. Whereas the third √n considers the factor of summing the √n chunks.

6. What will be the time complexity of update query operation in an array of size n when we use square root optimization?
a) O(√n)
b) O(n)
c) O(1)
d) O(n2)
View Answer

Answer:c
Explanation: The time complexity of query operation remains the same in both square root optimized code and non optimized code. We simply find the chunk in which the update requires to be performed and then add the new updated value at the desired index.

7. Square root decomposition technique is only applicable when the number of indices in an array is a perfect square.
a) true
b) false
View Answer

Answer: b
Explanation: Square root decomposition technique can be applied to an array with any number of indices. It does not require this number to be a perfect square.

8. What will be the worst case time complexity of code to find sum in given query range (l,r) in an array of size n with q number of such queries?
a) O(n)
b) O(q)
c) O(n*q)
d) O(n+q)
View Answer

Answer: c
Explanation: For finding the result of one query the worst case time complexity will be n. So for q queries the time complexity will be O(q*n). This can be reduced by using square root optimization.

9. What will be the worst case time complexity of code to find sum in given query range (l,r) in an array of size n with q number of such queries when we apply MO’s algorithm?
a) O(n*q)
b) O(n)
c) O((q+n)√n)
d) O(q*√n)
View Answer

Answer: c
Explanation: Mo’s algorithm requires O(q*√n) + O(n*√n) time for processing all the queries. It is better than the naive solution where O(n*q) time is required.

10. Mo’s algorithm can only be used for problems where the query can be calculated from the result of the previous query.
a) true
b) false
View Answer

Answer: a
Explanation: Mo’s algorithm uses the result of the previous query in order to compute the result of the given query. It cannot be implemented where such a scenario is not possible.

11. What will be the time complexity of the code to find a minimum element from an array of size n and uses square root decomposition(exclude pre processing time)?
a) O(√n)
b) O(n)
c) O(1)
d) O(n2)
View Answer

Answer: a
Explanation: For finding the minimum element in a given array of size n using square root decomposition we first divide the array into √n chunks and calculate the result for them individually. So for a given query, the result of middle blocks has to be calculated along with the extreme elements. This takes O(√n) time in the worst case.

Sanfoundry Global Education & Learning Series – Data Structures & Algorithms.

To practice all areas of Data Structures & Algorithms, here is complete set of 1000+ Multiple Choice Questions and Answers.



Source link

Filed Under: c programming Tagged With: •   Array-Recursion-Min-Max, •   Array-Recursion-Search - 1, •   Array-Recursion-Search - 2, •   Assembly Line Scheduling, •   Balanced Partition, •   Best First Search, •   Binary Search Iterative, •   Binary Tree Sort, •   Bipartite Graph, •   Bipartite Graphs Properties, •   Bogosort, •   Boolean Parenthesizations, •   Bottom Up Mergesort, •   Breadth First Search, •   Catalan Number, •   Chan's Algorithm, •   Closest Pair Problem, •   Co-ordinate Compression, •   Coin Change Problem, •   Comb Sort, •   Complete Bipartite Graph, •   Continuous Subarray - 1, •   Continuous Subarray - 2, •   Counting Sort, •   Decimal-Binary Conversion, •   Depth First Search, •   Dice Throw Problem, •   Digits Sum - Recursion, •   Dijkstra's Algorithm, •   Dynamic Programming, •   Edit Distance Problem, •   Eight Queens Problem, •   Euclid's Algorithm, •   Factorial using Recursion, •   Fibonacci Term, •   Fibonacci using Recursion, •   First-in First-out Algorithm, •   Fraction Knapsack Problem, •   GCD & LCM Recursion - 1, •   GCD & LCM Recursion - 2, •   Generating Combinations, •   Generating Partitions, •   Generating Permutations, •   Generating Subsets, •   Gnome Sort, •   Hamiltonian Path Problem, •   Hamming Code, •   Heapsort - 1, •   Heapsort - 2, •   Huffman Code, •   In-place Merge Sort, •   Inclusion Principle, •   Insertion Sort - 1, •   Insertion Sort - 2, •   Introsort, •   Jump Search, •   Kruskal's Algorithm, •   Linear Search Iterative, •   Linear Search Recursive, •   Linkedlist-Length-Recursion, •   Linkedlist-Recursion-Search, •   Lists-Recursion-Min-Max, •   Longest Subsequence, •   LSD Radix Sort, •   Matrix Multiplication, •   Max Bipartite Matching, •   Maximum Flow Problem, •   Minimum Cut, •   Minimum Number of Jumps, •   Minimum Spanning Tree, •   Monoalphabetic Cipher, •   Morse Code - 1, •   Morse Code - 2, •   N Queens Problem, •   Natural No's - Recursion, •   Non-recursive DFS, •   NP Complexity Classes, •   Number Power - Recursion, •   Odd-Even Sort, •   Optimal Page Replacement, •   Palindrome Min Insertions, •   Palindromic Subsequence, •   Pancake Sort, •   Permutation Sort, •   Polyalphabetic Cipher, •   Prim's Algorithm, •   Quick Search Algorithm, •   Quickhull, •   Quickselect, •   Quicksort - 1, •   Quicksort - 2, •   Quicksort - 3, •   Quicksort using Sampling, •   Rabin-Karp Algorithm, •   Rectangle Sum in 2D Matrix, •   Recursive Selection Sort, •   Rod Cutting, •   Selection Sort, •   Shell Sort - 1, •   Shell Sort - 2, •   Sleep Sort, •   Square Root Decomposition, •   Stable Marriage Problem, •   Stack Reversal - Recursion, •   Strassen's Algorithm, •   String Length - Recursion, •   String Reversal - Recursion, •   Timsort, •   Topological Sorting, •   Towers of Hanoi - Recursion, •   Uniform Binary Search, •   Vigenere Cipher, •   Wagner-Fischer Algorithm, 0 - 1 Knapsack Problem, 1000 C Questions & Answers, 1000 Hadoop Questions, 1000 Java Questions & Answers, 1000 Linux Questions & Answers, 1000 PHP Questions & Answers, 1000 Python Questions, About, About Us, Advanced C Training, Aeronautical, Aerospace, Agriculture, Algorithm & Programming Books, All Stream Best Books, All Stream Internships, All Stream Questions & Answers, Backtracking, Bangalore Training, BCA, Bellman–Ford Algorithm, Biotechnology, Bubble Sort, C Program to find the Lowest Common Ancestor of a given Binary Search Tree, C Programming Examples on Arrays, C Programming Examples on Combinatorial Problems & Algorithms, C Programming Examples on Numerical Problems & Algorithms, C# Programming Examples on LINQ, Chemical, Chemical Engineering Books, Chemical Internships, Civil, Civil Engineering Books, Civil Internships, Cloud Computing Questions, Co-ordinate Compression Multiple Choice Questions and Answers (MCQs), Computer Science Books, Computer Science Internships, Computer Science Questions, Contact, Contact Us, Copyright, CS, Data Structures & Algorithms Books, Database Management System Questions and Answers, Developer Tracks, Developers Track, ECE, EE, EEE, Electrical Engineering Books, Electrical Internships, Electronics Engineering Books, Electronics Internships, Facebook, Fibonacci Search, Floyd Warshall Algorithm, GDB Assignment, here is complete set of 1000+ Multiple Choice Questions and Answers, Home, Industrial Engineering Books, Industrial Internships, Instrumentation, Instrumentation Engg Books, Instrumentation Internships, Internship, IS, IT, IT Internships, Java Programming Examples on Arrays, Java Programming Examples on Numerical Problems & Algorithms, Jobs, Kadane's Algorithm, Kernel Debugging, Kernel Programming, LinkedIn, Linux Device Drivers, Linux Driver Developer, Linux Fundamentals, Linux Kernel Developer, Linux Network Developer, Linux Threads, Linux-C Debugging, Live Training Photos, Manish, Manish Bhojasia, Marine, Matrix Chain Multiplication, MCA, Mechanical, Mechanical Engineering Books, Mechanical Internships, Mentoring, Mentoring Sessions, Metallurgical Engineering Books, Metallurgy, Mining, Network Programming, Online Training, Prev Page, Prev Page - Co-ordinate Compression Multiple Choice Questions and Answers (MCQs), Privacy Policy, Programming, Python Programming Examples on Trees, RDBMS Questions and Answers, Recursion, SAN Developer, SAN I - Technology, SAN II - Admin, Sitemap, Software Productivity, System Programming, Systems Internships, Terms, Test & Rank, Training, Twitter

TCS NQT 2018 (Recruitment Exam)

Leave a Comment


I am from “Institute of Engineering and Management, Kolkata”.

Round 1: TCS conducted a National Qualifier Test (NQT) as the first round of recruitment process this year. There was no concept of Campus Recruitment had happened this year. They fixed two specific dates for this NQT exam that was 2nd September 2018 and 3rd September 2018. There were 3 slots for each day. Question sets were the same for all for the same slot but different for either slot.

There were four sections in that online exam with sectional cut offs. four sections are 1. English test 2. Aptitude test 3. Computer proficiency test 4. Coding test.

My slot timing was in the 3rd slot on 2nd. English section was pretty much normal basically fill in the blanks type. In the aptitude section, there are two subsections one is normal and another is advanced. Computer proficiency section was also the same type and many questions were asked from ds and c-programming code snippet. And the last section was the Coding section.

Results were declared via mail on 8th September and I was luckily qualified in the first round. From our college, almost 650 students appeared for that exam and 413 students are qualified for the F2F interview.

Round 2: On the very next day of the first round result declaration I got another mail from TCS for the Interview date and place which was conducted on TCS Gitanjali Park office, Kolkata.

I had my interview on 11th September from 12 p.m and onwards. I arrived at the TCS office at 11.30 a.m. After waiting for a long I got my call around 4.15 p.m.

Now here I am going to share my interview experience. I will write interviewer 1 as I1, interviewer 2 as I2 and myself as M :

.

.

M: May I come in?

I1: Yes.

M: Good afternoon sir, good afternoon ma’am.

<< without giving any reply back >>

I1: Mainak, tell me the basic difference between the Ipv4 and Ipv6?

<<I have not mentioned “networking” in my resume >>

M: …. somehow manage to answer very basic.

I1: Seems not so happy. ” you are giving an answer, like a class 5 child”. Then again asked a question from networking.

I1: what is your final semester subsects?

M: After a big pause… Sorry, sir! I don’t know as currently, I am in 7th sem.

I1: So what is your 7th sem subjects and 6th sem subjects?

M: Ans with confidence.

<<As I was not prepared for this kind of questions. I lose my confidence took permission for having some water in between the interview process>>

I1: Final year project related questions

M: Ans with confidence.

I1: DBMS related questions

M: Answer

I1: Questions related to Extracurricular activities and some questions related to marketing.

M: Manage to answer every question.

<In between this I2 was only observing me and my answers…. Not a single question was asked by her>

After the Interview, I was asked to wait outside. Again after waiting a long I was asked to leave for the day.

.

.

A few days later, results out and as expected my name was not there in the list.

From the 413 qualified students, only 192 students got the offer letter.

I can say Luck really matters a lot in case of every interview. If you get a good panel you will be hired easily.

Best Of Luck!!!!!!!!!!!!!

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
1

Please write to us at [email protected] to report any issue with the above content.


Post navigation


Previous

first_page Oyo Interview Experience

Next

last_page Goldman Sachs Interview Experience (On-campus for Summer Internship)







Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, 0 - 1 Knapsack Problem, 1s and 2s, About Us, Add two numbers represented by linked lists, Adobe, Adobe Practice Problems, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Amazon, Amazon Practice Problems, Analysis of Algorithms, Aptitude, Array, Arrays, Backtracking, BFS, BFS Traversal, Binary Search, Binary Search Tree, Binary Tree, Bit Algorithms, Bit Magic, Branch & Bound, C, C++ Quiz, Campus Ambassador Program, Careers, Check for Balanced Tree, Check if a number is Bleak, Check if a number is power of another number, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Connect Nodes at Same Level, Consecutive 1's not allowed, Contact Us, Contests, contribute.geeksforgeeks.org, Core Subjects ►, Courses, CPP Functions, CS Subjects, CS Subjects ▼, CS Subjectwise ►, D E Shaw, Data Structures, DBMS, Design Patterns, Detect a negative cycle., DFS, Dictionary, Digital Electronics, Directi, Directi Practce Problems, Divide and Conquer, DS ▼, Egg Dropping Puzzle, Engg. Mathematics, Experienced Interviews, Find Nth root of M, Find the number of islands, Finding middle element in a linked list, Flattening a Linked List, Flipkart, Flipkart Practice Problems, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE CS Notes, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Geeks Classes, General Electric (GE) | Campus selections for EEDP program, Geometric, Geometric Algorithms, Goldman Sachs, Goldman Sachs Interview Experience, Goldman Sachs Interview Experience (On-campus for Summer Internship), Goldman Sachs Interview Experience | (On campus Internship for Operations profile), Graph, Graph Algorithms, Greedy Algorithms, Hash, Hashing, Heap, HeapSort, How to begin with Competitive Programming?, How to prepare for ACM-ICPC?, HTML & XML, ide.geeksforgeeks.org, Implement a stack with push(), Implement Queue using Linked List, Implement Stack using Queues, Insertion Sort, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, Inversion of array, Is Binary Number Multiple of 3, ISRO, ISRO CS Exam, Java, Java Collections, Java-Functions, Java.lang package, Java.util Package, JavaScript, Jumping Numebrs, K distance from root, k largest elements, Kadane's Algorithm, Key Pair, Languages, Languages ►, Languages ▼, Last Minute Notes, Left View of Binary Tree, Level Order traversal, Linked List, Linkedin Internship Interview Experience, LinkedList, Longest Increasing Subsequence, Longest Palindromic Subsequence, Longest Repeated Subsequence, Machine Learning, Mathematical, Mathematical Algorithms, Matrix, Max Sum without Adjacents, Maximum of all subarrays of size k, Maximum Width of Tree, MergeSort, Microprocessor, Microsoft, Microsoft IDC Interview Experience, Microsoft Practice Problems, Mirror Tree, More Company Interview Experiences, More Company-wise Practice Problems, Multiple Choice Quizzes, Must Do Coding Questions Company-wise, Must Do Coding Questions Topic-wise, Next greater number set digits, Non Repeating Character, Number Theory, Nutanix Interview Experience 2018, Ola Cabs, Ola Cabs Practice Problems, On-Campus, Operating Systems, Oracle, Oracle Practice Problems, Oyo Interview Experience, Pattern Searching, Paytm, Paytm Practice Problems, Permutations of a given string, PHP, PHP-function, Placement Course, pop() and min() in O(1) time, Possible words from Phone digits, Practice Company Questions, Privacy Policy, Program Output, Project, Puzzles, Python, Python List, QA - Placement Quizzes, Qualcomm, Queue, QuickSort, Quizzes ▼, Randomized Algorithms, Remove duplicate element from sorted Linked List, Remove every k'th node, Remove Spaces from string, Reverse a Linked List in groups of given size, Reverse Level Order Traversal, Reverse words in a given string, Right View of Binary Tree, Root to leaf path sum, Samsung, Samsung 6 month Internship Interview, Samsung Practice Problems, SAP Labs, SAP Labs Interview (Off Campus for Associate Developer), SAP Labs Practice Problems, Sapient | campus selections for Associate Software Development Engineer I, School Programming, Search in a matrix, Search in a Rotated Array, Searching, Searching Algorithms, Second Largest, series, Set, Set to Array in Java, Skip to content, Software Engineering, Solve the Sudoku, Some rights reserved, Sort an array of 0s, Sorting, Sorting Algorithms, SQL, Stack, Step by Step Guide for Placement Preparation, STL, Strings, Students ▼, Subjective Questions, Subset Sum Problem, Suggest a Topic, TCS, TCS CodeVita 2018 Interview Experience, TCS Ninja Interview Experience and Interview Questions, TCS-interview-experience, Technical Scripter, Testimonials, Theory of Computation, Top 10 algorithms in Interview Questions, Top Topics, Topic-wise, Topicwise ►, Tree, Tree based DS ►, Tuple, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, UGC-NET, Video Tutorials, Videos, VMware Interview Experience | Set 13 (On-Campus): Rnd_developer, Web Technologies, Web Technology, What’s Difference?, Word Boggle, Write an Article, Write Interview Experience, Write your Interview Experience, Zomato Interview Experience, ZS Associates for Software Engineer

Ways to write N as sum of two or more positive integers | Set-2

Leave a Comment


Given a number N, the task is to find the number of ways N can be partitioned, i.e. the number of ways that N can be expressed as a sum of positive integers.

Note: N should also be considered itself a way to express it as a sum of positive integers.
Examples:

Input: N = 5
Output: 7
5 can be partitioned in the following ways:
5
4 + 1
3 + 2
3 + 1 + 1
2 + 2 + 1
2 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1

Input: N = 10
Output: 42

This post has been already discussed in Ways to write n as sum of two or more positive integers. In this post, an efficient approach is discussed.

Approach(Using Euler’s recurrence):
If p(n) is the number of partitions of N, then it can be generated by the following generating function:

Using this formula and Euler’s pentagonal number theorem, we can derive the following recurrence relation for p(n): (Check the Wikipedia article for more details)

where k = 1, -1, 2, -2, 3, -3, … and p(n) = 0 for n < 0.

Below is the implementation of above approach:

#include <bits/stdc++.h>

using namespace std;

long long partitions(int n)

{

vector<long long> p(n + 1, 0);

p[0] = 1;

for (int i = 1; i <= n; ++i) {

int k = 1;

while ((k * (3 * k - 1)) / 2 <= i) {

p[i] += (k % 2 ? 1 : -1) * p[i - (k * (3 * k - 1)) / 2];

if (k > 0)

k *= -1;

else

k = 1 - k;

}

}

return p[n];

}

int main()

{

int N = 20;

cout << partitions(N);

return 0;

}

Time Complexity: O(N√N)
Space Complexity: O(N)



If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the “Improve Article” button below.

Article Tags :


thumb_up
Be the First to upvote.

Please write to us at [email protected] to report any issue with the above content.


Post navigation










Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, 0 - 1 Knapsack Problem, A Space Optimized DP solution for 0-1 Knapsack Problem, About Us, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, Algorithms-Recursion, All Algorithms, All Data Structures, Amazon, Analysis of Algorithms, Aptitude, Array, Arrays, Backtracking, Bell Numbers, Bellman–Ford Algorithm, BFS, Binary Search, Binary Search Tree, Binary Tree, Binomial Coefficient, Bit Algorithms, Bit Magic, Bitmasking and Dynamic Programming | Set 1 (Count ways to assign unique cap to every person), Bitmasking and Dynamic Programming | Set-2 (TSP), Boolean Parenthesization Problem, Box Stacking Problem, Branch & Bound, Bridge and Torch problem, Burst Balloon to maximize coins, C, C++ Quiz, Campus Ambassador Program, Careers, Check whether row or column swaps produce maximum size binary sub-matrix with all 1s, Choice of Area, Coin Change, Company Prep, Company-wise, Competitive Programming, Compiler Design, Compute nCr % p, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Contact Us, Contests, contribute.geeksforgeeks.org, contributed articles, Core Subjects ►, Count common subsequence in two strings, Count numbers (smaller than or equal to N) with given digit sum, Count of AP (Arithmetic Progression) Subsequences in an array, Count the number of ways to traverse a Matrix, Count ways to increase LCS length of two strings by one, Courses, CPP Functions, CPP-Library, CS Subjects, CS Subjects ▼, CS Subjectwise ►, Cutting a Rod, Data Structures, DBMS, Delannoy Number, Design Patterns, Detect a negative cycle., DFS, Dice Throw, Dictionary, Digit DP | Introduction, Digital Electronics, Divide and Conquer, DS ▼, Egg Dropping Puzzle, Engg. Mathematics, Entringer Number, Eulerian Number, Experienced Interviews, Explore More..., Fibonacci Numbers, Find maximum points which can be obtained by deleting elements from array, Floyd Warshall Algorithm, Friends Pairing Problem, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE CS Notes, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Geeks Classes, Geometric, Geometric Algorithms, Gold Mine Problem, Golomb sequence, Graph, Graph Algorithms, Greedy Algorithms, Hash, Hashing, Heap, HeapSort, Highway Billboard Problem, How to begin with Competitive Programming?, How to prepare for ACM-ICPC?, How to solve a Dynamic Programming Problem ?, HTML & XML, ide.geeksforgeeks.org, Insertion Sort, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, ISRO, ISRO CS Exam, Jacobsthal and Jacobsthal-Lucas numbers, Java, Java Collections, Java-Functions, Java.lang package, Java.util Package, JavaScript, K maximum sums of overlapping contiguous sub-arrays, Languages, Languages ►, Languages ▼, Largest divisible pairs subset, Largest Independent Set Problem, Largest rectangular sub-matrix having sum divisible by k, Largest rectangular sub-matrix whose sum is 0, Last Minute Notes, Linked List, LinkedList, Lobb Number, Longest Bitonic Subsequence, Longest dividing subsequence, Longest palindrome subsequence with O(n) space, Longest Palindromic Subsequence, Longest Repeated Subsequence, Machine Learning, Mathematical, Mathematical Algorithms, Matrix, Matrix Chain Multiplication, Matrix Chain Multiplication (A O(N^2) Solution), maximum length Snake sequence, Maximum points from top left of matrix to bottom right and return back, Maximum profit by buying and selling a share at most k times, Maximum sum bitonic subarray, MergeSort, Microprocessor, Microsoft, Minimum cost to buy N kilograms of sweet for M persons, Minimum Cost to make two Numeric Strings Identical, Minimum number of elements which are not part of Increasing or decreasing subsequence in array, Minimum number of increasing subsequences, Minimum number of palindromes required to express N as a sum | Set 1, Minimum number of palindromes required to express N as a sum | Set 2, Minimum odd cost path in a matrix, Mobile Numeric Keypad Problem, Moser-de Bruijn Sequence, Multiple Choice Quizzes, Newman-Conway Sequence, nth Catalan Number, Number of palindromic paths in a matrix, Number Theory, Operating Systems, Optimal Substructure Property, Overlapping Subproblems Property, Painting Fence Algorithm, Palindrome Partitioning, Pattern Searching, Perfect Sum Problem, Permutation Coefficient, PHP, PHP-function, Placement Course, Practice Company Questions, Practice Problems, Print equal sum sets of array (Partition problem) | Set 1, Print Fibonacci sequence using 2 variables, Print Longest Palindromic Subsequence, Printing brackets in Matrix Chain Multiplication Problem, Printing Items in 0/1 Knapsack, Printing Longest Bitonic Subsequence, Printing Matrix Chain Multiplication (A Space Optimized Solution), Privacy Policy, Program Output, Project, Puzzles, Python, Python List, QA - Placement Quizzes, Queue, QuickSort, Quizzes, Quizzes ▼, Randomized Algorithms, Recent Articles, Recommended: Please try your approach on, Rencontres Number, School Programming, Searching, Searching Algorithms, series, Set, Set 2, Set to Array in Java, Skip to content, Software Engineering, Some rights reserved, Sorting, Sorting Algorithms, SQL, Stack, Step by Step Guide for Placement Preparation, STL, Strings, Students ▼, Subjective Questions, Subset Sum Problem, Subset Sum Problem in O(sum) space, Subset with sum divisible by m, Suggest a Topic, Super Ugly Number, Tabulation vs Memoizatation, Technical Scripter, Technical Scripter 2018, Temple Offerings, Testimonials, The painter’s partition problem, Theory of Computation, Tile Stacking Problem, Tiling Problem, Tiling with Dominoes, Top 10 algorithms in Interview Questions, Top Topics, Topic-wise, Topicwise ►, Tree, Tree based DS ►, Tuple, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, UGC-NET, Ugly Numbers, Unbounded Knapsack, Vertex Cover Problem, Video Tutorials, Videos, Walmart Labs Interview Experience ( On Campus FT + 6 month Internship ), Ways to write n as sum of two or more positive integers, Web Technologies, Web Technology, What’s Difference?, Wikipedia article, Word Break Problem, Word Wrap Problem, Write an Article, Write Interview Experience

Cohesity internship interview

Leave a Comment


Round 1:
The first round was an online round held on Hackerearth. It had 2 questions of easy-medium level.
Easliy solvable with decent coding skills.

Round 2:
This was a Zoom online interview round lasting for about 45 mins. The interviewer went through my resume and asked me to describe my projects.
Tip : Know about each word in your resume and each word you speak in detail.

He then gave me 2 algorithmic problems:

1st problem : Find the longest palindromic substring in the given string. I gave him the standard DP approach of O(n^2) time and space complexity. He asked me to improve my space complexity. I told him the idea, but was asked to write the code the O(n2) solution itself.
Simple approach
Optimized approach
2nd problem : Given x and y, find the numbers between x and y which do not have repetitive digits in them.
https://www.geeksforgeeks.org/total-numbers-no-repeated-digits-range/

Round 3:
This also was a Zoom online interview round lasting for about 30 mins with a different person. I introduced myself and was asked the following question –
Consider all 3 letter words in a dictionary. Given a source and destination word, and that the cost of changing a letter in a word at a time is 1, find the minimum cost to reach destination from source by changing only one letter at a time.
https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/
He then asked me questions about my projects, past internship, DBMS and OS.

Got the offer 🙂


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Article Tags :

Please write to us at [email protected] to report any issue with the above content.


Post navigation









Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, 0 - 1 Knapsack Problem, 1s and 2s, About Us, Add two numbers represented by linked lists, Adobe, Adobe Practice Problems, Advanced Data Structure, Advanced Topics, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, Amazon, Amazon Practice Problems, Analysis of Algorithms, Aptitude, Arcesium Interview Experience 2018 ( Intern, Arista Networks Internship (On campus), Array, Arrays, Backtracking, BFS, BFS Traversal, Binary Search, Binary Search Tree, Binary Tree, Bit Algorithms, Bit Magic, Branch & Bound, BuyHatke interview experience (On-campus for 6 months internship), C, C++ Quiz, Campus Ambassador Program, Careers, Check for Balanced Tree, Check if a number is Bleak, Check if a number is power of another number, Cohesity, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Connect Nodes at Same Level, Consecutive 1's not allowed, Contact Us, Contests, contribute.geeksforgeeks.org, Core Subjects ►, Courses, CPP Functions, CS Subjects, CS Subjects ▼, CS Subjectwise ►, D E Shaw, Data Structures, DBMS, Design Patterns, Detect a negative cycle., DFS, Dictionary, Digital Electronics, Directi, Directi Practce Problems, Divide and Conquer, DS ▼, Egg Dropping Puzzle, Engg. Mathematics, Experienced Interviews, Find Nth root of M, Find the number of islands, Finding middle element in a linked list, Flattening a Linked List, Flipkart, Flipkart Practice Problems, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE CS Notes, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Geeks Classes, Geometric Algorithms, Goldman Sachs, Graph, Graph Algorithms, Greedy Algorithms, Hash, Hashing, Heap, HeapSort, How to begin with Competitive Programming?, How to prepare for ACM-ICPC?, HTML & XML, https://www.geeksforgeeks.org/total-numbers-no-repeated-digits-range/, https://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/, ide.geeksforgeeks.org, Implement a stack with push(), Implement Queue using Linked List, Implement Stack using Queues, Insertion Sort, Internship, Internship Interview Experiences Company-Wise, Internship Interviews, Internships, Interview ▼, Interview Experiences, Inversion of array, Is Binary Number Multiple of 3, ISRO, ISRO CS Exam, Java, Java Collections, Java-Functions, Java.lang package, Java.util Package, JavaScript, Jumping Numebrs, K distance from root, k largest elements, Kadane's Algorithm, Key Pair, Languages, Languages ►, Languages ▼, Last Minute Notes, Left View of Binary Tree, Level Order traversal, Linked List, LinkedList, Login, Longest Increasing Subsequence, Longest Palindromic Subsequence, Longest Repeated Subsequence, Machine Learning, Mathematical, Mathematical Algorithms, Matrix, Max Sum without Adjacents, Maximum of all subarrays of size k, Maximum Width of Tree, MergeSort, Microland interview experience (on-campus internship + FTE), Microprocessor, Microsoft, Microsoft Interview Experience (For Internship), Microsoft Interview Experience (Internship 2018), Microsoft Practice Problems, Mirror Tree, More Company Interview Experiences, More Company-wise Practice Problems, Multiple Choice Quizzes, Must Do Coding Questions Company-wise, Must Do Coding Questions Topic-wise, Next greater number set digits, Non Repeating Character, Number Theory, Ola Cabs, Ola Cabs Practice Problems, On-Campus, Operating Systems, Optimized approach, Oracle, Oracle Practice Problems, Pattern Searching, Paytm, Paytm Practice Problems, Permutations of a given string, PHP, PHP-function, Placement Course, pop() and min() in O(1) time, Possible words from Phone digits, Practice Company Questions, Privacy Policy, Program Output, Project, Puzzles, Python, Python List, QA - Placement Quizzes, Qualcomm, Queue, QuickSort, Quizzes ▼, Randomized Algorithms, Remove duplicate element from sorted Linked List, Remove every k'th node, Remove Spaces from string, Reverse a Linked List in groups of given size, Reverse Level Order Traversal, Reverse words in a given string, Right View of Binary Tree, Root to leaf path sum, Samsung, Samsung Practice Problems, SAP Labs, SAP Labs Practice Problems, School Programming, Search in a matrix, Search in a Rotated Array, Searching, Searching Algorithms, Second Largest, series, Set, Set to Array in Java, Simple approach, Skip to content, Software Engineering, Solve the Sudoku, Some rights reserved, Sort an array of 0s, Sorting, Sorting Algorithms, SQL, Stack, Step by Step Guide for Placement Preparation, STL, Strings, Students ▼, Subjective Questions, Subset Sum Problem, Sudo Placement 2, Suggest a Topic, Technical Scripter, Testimonials, Theory of Computation, Top 10 Algorithms and Data Structures for Competitive Programming, Top 10 algorithms in Interview Questions, Top Topics, Topic-wise, Topicwise ►, Tree, Tree based DS ►, Tuple, Uber Interview Experience (On Campus for Internship 2018-19), UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, UGC-NET, UnitedHealth group Optum Internship Experience, Video Tutorials, Videos, VMware On-Campus for Internship, Web Technologies, Web Technology, What’s Difference?, Word Boggle, Write an Article, Write Interview Experience, Write your Interview Experience

Primary Sidebar

Recent Posts

  • How to use optional in java 8 streams
  • 7 Must-Have Mobile Apps to Prepare for Online Interviews
  • Top 10 Most Popular JavaScript Frameworks for Web Development
  • Angular 9 features with examples
  • Popular Programming Languages Supported by AWS
  • Privacy Policy
  • About
  • Contact US

© 2019 ProProgramming
 Privacy Policy About Contact Us