Quick Revision

GK One-Line Question & Answer

15541+ short questions with short answers, covering every category and sub-category on the site — no long articles to scroll through. Good for a fast recap before an exam, or a few minutes of daily practice.

Data Structures and Algorithms → Introduction to DSA 37

Boyer-Moore algorithm searches string from:
Right to left (more efficient skips)
click to copy
Aho-Corasick algorithm enables:
Multiple pattern search simultaneously in O(n+m+z)
click to copy
Z-algorithm computes for each position:
Length of longest substring starting from position that is also a prefix
click to copy
Manacher algorithm finds:
Longest palindromic substring in O(n)
click to copy
Two-pointer technique is used for:
Efficiently solving array/string problems with two indices moving toward each other
click to copy
Sliding window technique is used for:
Finding optimal subarray/substring of fixed or variable size
click to copy
Kadane algorithm maintains:
Current subarray sum and global maximum
click to copy
The stock buy-sell problem (one transaction) is solved in:
O(n) by tracking minimum price seen so far
click to copy
Finding majority element (appearing > n/2 times) is solved by:
Boyer-Moore Voting Algorithm in O(n)
click to copy
Reservoir sampling is used for:
Randomly selecting k items from stream of unknown size in O(n)
click to copy
The output of: int x=5; cout<<((x%2)==0?"Even":"Odd");
Odd
click to copy
The output of: int n=100; int sum=n*(n+1)/2; cout<<sum;
5050
click to copy
The output of: int a=10,b=5; a=a^b; b=a^b; a=a^b; cout<<a<<" "<<b;
5 10
click to copy
The output of: for(int i=1;i<=5;i++) cout<<i*(i+1)/2<<" ";
1 3 6 10 15
click to copy
The output of: int n=16; while(n>1){n/=2; cout<<n<<" ";}
8 4 2 1
click to copy
The output of: int x=255; cout<<(x & 0x0F);
15
click to copy
The output of: int x=170; cout<<(x & 0xFF)<<" "<<(x>>4);
170 10
click to copy
The output of: int n=7; cout<<__builtin_popcount(n);
3
click to copy
The output of: cout<<__builtin_clz(8); on 32-bit int?
28
click to copy
The output of: int x=12; cout<<(x&(x-1));
8
click to copy
n & (n-1) equals 0 iff n is:
Power of 2 (or n=0)
click to copy
What is the output: cout<<(0b1010 | 0b1100);
14
click to copy
What is the output: cout<<(0b1010 & 0b1100);
8
click to copy
What is the output: cout<<(0b1010 ^ 0b1100);
6
click to copy
The output of: cout<<~0;
-1
click to copy
What is the output: int x=0x1234; cout<<((x>>8)&0xFF)<<" "<<(x&0xFF);
18 52
click to copy
The output of: float f=3.14f; int i=*(int*)&f; is:
A specific integer bit pattern (type punning)
click to copy
Which is correct for checking if number is even without %?
All equivalent
click to copy
The output of: int a=3,b=3; cout<<(a==b && !(a^b));
1
click to copy
To multiply by 4 using bit shift:
n<<2 (left shift by 2 = multiply by 2^2=4)
click to copy
To divide by 8 using bit shift:
n>>3 (right shift by 3 = divide by 2^3=8)
click to copy
The output of: int x=100; cout<<(x/10)<<(x%10);
100
click to copy
The output of: string s=""; for(int i=65;i<70;i++) s+=(char)i; cout<<s;
ABCDE
click to copy
Which OOP concept is violated when a class has public data members?
Encapsulation (data hiding)
click to copy
What is cohesion in software design?
Degree to which a class/module has a single, focused purpose
click to copy
What is coupling in software design?
Degree of interdependence between modules (lower is better)
click to copy
High cohesion and low coupling is:
Good design (focused modules, minimal interdependence)
click to copy

Data Structures and Algorithms → Arrays 3

Suffix array is used for:
Efficient string operations (search, LCP) by storing sorted suffixes
click to copy
The maximum subarray sum problem is solved by:
Kadane algorithm in O(n)
click to copy
Dutch National Flag problem sorts array of 0s, 1s, 2s in:
O(n) using three-way partitioning
click to copy