Check existence of pair with given sum in array
Duration: 5 min
This video lesson is available to enrolled students.
Inside: a video lesson and guided study material.
Module outline
- Quantitative Aptitude: Number System, Divisibility Rules, HCF LCM, Percentage, Ratio and Proportion (Ratios), Average, Profit and Loss, Simple Interest and Compound Interest, Mixture and Alligation, Partnership, Age Problems, Time and Work, Pipe and Cistern, Speed Time and Distance, Algebra, Arithmetic, Data Interpretation, Sequence and Series (Series), Logarithm, Powers and Exponents (Surds and Indices), Permutation and Combination, Probability, Speed Mathematics and Basic Mathematics, Trigonometry
- Logical Reasoning: Coding Decoding, Blood Relations, Directions (Direction Test), Ranking, Order and Sequence, Seating Arrangements, Puzzle Solving (Puzzles), Data Arrangement, Syllogisms, Inequality, Data Sufficiency, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Series (Number and Letter Series) (Numerical Relations and Reasoning), Venn Diagram, Logical Sequence Of Words, Calendar, Clock, Cubes & Dices, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning)
- Verbal Ability: Noun, Pronoun, Adjectives, Verb, Adverb, Tenses, Subject Verb Agreement (Verb Noun Agreement), Articles, Preposition, Conjunction, Modals, Determiner, Vocabulary, Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Cloze Test (Cloze Passage), Sentence Correction (Error Correction), Sentence Completion (Fill in the blanks), Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Active Passive Voice (Voice), Direct and Indirect Speech, Sentence Construction
- Data Structures (Domain Test): Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
- Algorithms (Domain Test):
- OOPs (Domain Test): Object Oriented Programming (OOPS)
- DBMS (Domain Test): Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, Relational Calculus, Transaction Management, Concurrency Control, Database Recovery, ORDBMS, Database Security & Authorization, Query Processing & Optimization, Enhanced Data Models, Data Warehousing & Mining, Big Data Systems, NoSQL
- SQL (Domain Test): SQL
- Operating Systems (Domain Test): Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Deadlock, Threads & Process Creation, Memory Management, Virtual Memory, Disc Scheduling, File Management, Windows OS, Linux OS, Security, Distributed Systems, Virtual Machines
- Computer Networks (Domain Test): Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware basics, Network Security, Cloud Computing and IoT, Cyber and Info Security
- Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Programming in C++, Java, Python for Placements by Yash Sir
- Written English Test: English Writing Ability
- Psychometric Test: Behavioral Assessment (Behavioral Competency Profiling) (Psychometric Test)
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This video is a programming tutorial that demonstrates an optimal algorithm to find a pair of elements in an array that sum to a given value. The lecture begins with an introduction to the problem, 'Program to check existence of pair with given sum in array (Naive Approach)', and then transitions to a more efficient 'Optimal Approach'. The instructor, a 'Placement Expert', explains the logic of sorting the array using quicksort and then applying a two-pointer technique. The code is written in C, with the main function calling a 'PairDetection' function that uses left and right pointers to traverse the sorted array. The video includes a live coding session on the GDB online compiler, where the algorithm is tested with the input array [2, 8, 1, 3, 4] and sum 9, successfully finding the pair (1, 8). The instructor also provides a complete C program with input/output handling and memory deallocation.
Chapters
0:00 – 2:00 00:00-02:00
The video starts with the 'KNOX MEEHEGATF' logo, which is a stylized version of 'KNOWLEDGE GATE'. It then transitions to a presentation slide showing the 'KNOWLEDGE GATE' brand and its social media handles for various educational topics like 'KG GATE & PLACEMENT PREP', 'KG CODING', and 'KG UGC NET COLLEGE PREP'. The main content begins with a PowerPoint slide titled 'Program to check existence of pair with given sum in array (Naive Approach)'. The instructor, identified as a 'PLACEMENT EXPERT' and 'Yash Jain Sir', introduces the problem and begins to explain the code. The screen shows a C code snippet with the function declaration 'int PairDetection(int A[], int arr_size, int sum)' and the start of its implementation, including variable declarations for left and right pointers and a call to 'quickSort(A, 0, arr_size - 1);'. A green box on the right side of the screen labels this as the 'Code (Optimal Approach)'.
2:00 – 5:00 02:00-05:00
The instructor continues to write and explain the C code for the 'Optimal Approach'. The code is displayed on a dark-themed editor. The function 'PairDetection' is shown with its parameters and the initialization of two pointers, 'l' and 'r', set to the start and end of the array. The core of the algorithm is a 'while' loop that runs as long as 'l < r'. Inside the loop, the sum of the elements at the two pointers is compared to the target sum. If the sum is equal, the function returns 1. If the sum is less than the target, the left pointer 'l' is incremented. If the sum is greater, the right pointer 'r' is decremented. The instructor uses a whiteboard to illustrate the logic with a sample array [2, 8, 1, 3, 4] and a target sum of 9, showing how the pointers move. The code is completed with a final 'return 0;' statement. The instructor then moves to the main function, showing how to prompt the user for input, call the 'PairDetection' function, and print the result. The code includes 'printf' and 'scanf' statements and a 'free(ptr);' statement for memory deallocation.
5:00 – 5:10 05:00-05:10
The video transitions to a live demonstration of the code in the GDB online compiler. The instructor runs the program with the input array [2, 8, 1, 3, 4] and a sum of 9. The output displayed in the console is 'Array has two elements with given sum', confirming that the algorithm correctly identified the pair (1, 8). The instructor concludes the demonstration, and the video ends with the GDB compiler interface visible on the screen.
The video provides a comprehensive, step-by-step tutorial on solving the 'two sum' problem using an optimal algorithm. It begins by introducing the problem and then systematically builds the solution, starting with the core logic of sorting the array and using a two-pointer technique. The instructor clearly explains the algorithm's logic, using both code and a whiteboard to illustrate the pointer movement. The lesson progresses from the theoretical explanation to a complete, runnable C program, which is then tested in a live environment to confirm its correctness. The synthesis of theory, code, and practical demonstration makes the concept accessible and reinforces the learning of an efficient algorithmic approach.

