SlideShare a Scribd company logo
Most
Asked TCS
Coding
By Prime Coding
Swap Two Numbers Without Using a Third
Variable
Let the numbers be a and b.
Use arithmetic operations to swap
them:
a = a + b
b = a - b
a = a - b
ALGORITH
M
Reverse a Given Number/String Using
Command Line Arguments
• Read the string from command line
arguments.
• Reverse the string using slicing or a loop.
• Print the reversed string.
ALGORITH
M
Arrange 1s and 0s Together in a Single Array
Scan
• Initialize two pointers, left and right, at the beginning and
end of the array.
• Scan the array with two pointers.
• Swap elements when a 0 is encountered at right and a 1 is
encountered at left.
• Move pointers inward.
ALGORITH
M
Function to Swap Two Numbers Without
Using a Temporary Variable
Use bitwise XOR to swap the values.
ALGORITH
M
def swap(a, b):
a = a ^ b
b = a ^ b
a = a ^ b
return a, b
Difference Between the Sum of Odd and Even
Position Digits
ALGORITH
M
• Initialize sum_odd and sum_even to 0.
• Iterate through each digit and add to the
corresponding sum based on the position.
Convert a Matrix into Lower Triangular Matrix
ALGORITH
M
Iterate over the matrix and set elements above the
main diagonal to 0.
Factorial of a Number Without Using
Arithmetic Operations
ALGORITH
M
Use recursive bit manipulation to compute the
factorial.
Number of Pairs Whose Average is Present in
the Array
ALGORITH
M
• Use a set to store unique elements.
• Iterate through each pair and check if their
average exists in the set.
Binary Search Algorithm
ALGORITH
M
• Initialize low to 0 and high to len(arr) - 1.
• While low is less than or equal to high:
• Calculate the mid index.
• If the target is equal to arr[mid], return the mid index.
• If the target is less than arr[mid], set high to mid - 1.
• If the target is greater than arr[mid], set low to mid +
1.
• If the target is not found, return -1.
Time & Space Complexity (Popular Sorting
and Searching Algorithms)
Sorting Algorithms:
• Bubble Sort: Time: O(n^2), Space: O(1)
• Selection Sort: Time: O(n^2), Space: O(1)
• Insertion Sort: Time: O(n^2), Space: O(1)
• Merge Sort: Time: O(n log n), Space: O(n)
• Quick Sort: Time: O(n log n) average, O(n^2) worst, Space: O(log
n)
• Heap Sort: Time: O(n log n), Space: O(1)
• Radix Sort: Time: O(nk), Space: O(n + k) (where k is the range of
Time & Space Complexity (Popular Sorting
and Searching Algorithms)
Searching Algorithms:
• Linear Search: Time: O(n), Space: O(1)
• Binary Search: Time: O(log n), Space: O(1)
Unique Paths in a Grid
ALGORITH
M
• Use dynamic programming.
• Create a 2D array dp where dp[i][j] represents the
number of unique paths to cell (i, j).
• Initialize the first row and column to 1.
• Fill the rest of the dp table using the relation dp[i][j] =
dp[i-1][j] + dp[i][j-1].
Minimum and Maximum Element in Every
Contiguous Subarray of Size k
ALGORITH
M
• Use two deques to maintain the indices of minimum
and maximum elements.
• Slide the window of size k over the array and update
the deques.
• At each step, record the current minimum and
maximum.
Rotate the Array by K Elements
ALGORITH
M
• Reverse the entire array.
• Reverse the first k elements.
• Reverse the remaining elements.
1:1 MOCK SESSIONS
Starting at Rs. 99
Get confident
Real life Experience
Crack interviews Fearlessly
Thank
you!
Prime Coding

More Related Content

Similar to TCS Coding questions of all the required section (20)

PPT
Counting sort(Non Comparison Sort)
Hossain Md Shakhawat
 
PPT
lecture 9
sajinsc
 
PPTX
02 Introduction to Data Structures & Algorithms.pptx
mettlehenry573
 
PPT
Polygon Fill
wahab13
 
PPTX
Area & Volume
GAURAV. H .TANDON
 
PPTX
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
SukhrobAtoev2
 
PDF
TuringMachines.pdf
viswanath kani
 
PPTX
UNIT1-part2.pptx
AshokRachapalli1
 
PPTX
Analysis of algorithms
MUSAIDRIS15
 
PPTX
SORT AND SEARCH ARRAY WITH WITH C++.pptx
narifmsit18seecs
 
PDF
220exercises2
sadhanakumble
 
PDF
GIS-DELAUNAY-GIS-DELAUNAY-GIS-DELAUNAY-GIS-DELAUNAY
ChannelRelaxation
 
PDF
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
PPTX
UNIT1-part2.pptx
AshokRachapalli1
 
PPTX
sorting-160810203705.pptx
VarchasvaTiwari2
 
PPT
Quicksort
Gayathri Gaayu
 
PPTX
quick sort by deepak.pptx
DeepakM509554
 
DOC
pradeepbishtLecture13 div conq
Pradeep Bisht
 
PPT
Cs1311lecture23wdl
Muhammad Wasif
 
PPTX
Sorting2
Saurabh Mishra
 
Counting sort(Non Comparison Sort)
Hossain Md Shakhawat
 
lecture 9
sajinsc
 
02 Introduction to Data Structures & Algorithms.pptx
mettlehenry573
 
Polygon Fill
wahab13
 
Area & Volume
GAURAV. H .TANDON
 
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
SukhrobAtoev2
 
TuringMachines.pdf
viswanath kani
 
UNIT1-part2.pptx
AshokRachapalli1
 
Analysis of algorithms
MUSAIDRIS15
 
SORT AND SEARCH ARRAY WITH WITH C++.pptx
narifmsit18seecs
 
220exercises2
sadhanakumble
 
GIS-DELAUNAY-GIS-DELAUNAY-GIS-DELAUNAY-GIS-DELAUNAY
ChannelRelaxation
 
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
UNIT1-part2.pptx
AshokRachapalli1
 
sorting-160810203705.pptx
VarchasvaTiwari2
 
Quicksort
Gayathri Gaayu
 
quick sort by deepak.pptx
DeepakM509554
 
pradeepbishtLecture13 div conq
Pradeep Bisht
 
Cs1311lecture23wdl
Muhammad Wasif
 
Sorting2
Saurabh Mishra
 

Recently uploaded (20)

PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Ad

TCS Coding questions of all the required section

  • 2. Swap Two Numbers Without Using a Third Variable Let the numbers be a and b. Use arithmetic operations to swap them: a = a + b b = a - b a = a - b ALGORITH M
  • 3. Reverse a Given Number/String Using Command Line Arguments • Read the string from command line arguments. • Reverse the string using slicing or a loop. • Print the reversed string. ALGORITH M
  • 4. Arrange 1s and 0s Together in a Single Array Scan • Initialize two pointers, left and right, at the beginning and end of the array. • Scan the array with two pointers. • Swap elements when a 0 is encountered at right and a 1 is encountered at left. • Move pointers inward. ALGORITH M
  • 5. Function to Swap Two Numbers Without Using a Temporary Variable Use bitwise XOR to swap the values. ALGORITH M def swap(a, b): a = a ^ b b = a ^ b a = a ^ b return a, b
  • 6. Difference Between the Sum of Odd and Even Position Digits ALGORITH M • Initialize sum_odd and sum_even to 0. • Iterate through each digit and add to the corresponding sum based on the position.
  • 7. Convert a Matrix into Lower Triangular Matrix ALGORITH M Iterate over the matrix and set elements above the main diagonal to 0.
  • 8. Factorial of a Number Without Using Arithmetic Operations ALGORITH M Use recursive bit manipulation to compute the factorial.
  • 9. Number of Pairs Whose Average is Present in the Array ALGORITH M • Use a set to store unique elements. • Iterate through each pair and check if their average exists in the set.
  • 10. Binary Search Algorithm ALGORITH M • Initialize low to 0 and high to len(arr) - 1. • While low is less than or equal to high: • Calculate the mid index. • If the target is equal to arr[mid], return the mid index. • If the target is less than arr[mid], set high to mid - 1. • If the target is greater than arr[mid], set low to mid + 1. • If the target is not found, return -1.
  • 11. Time & Space Complexity (Popular Sorting and Searching Algorithms) Sorting Algorithms: • Bubble Sort: Time: O(n^2), Space: O(1) • Selection Sort: Time: O(n^2), Space: O(1) • Insertion Sort: Time: O(n^2), Space: O(1) • Merge Sort: Time: O(n log n), Space: O(n) • Quick Sort: Time: O(n log n) average, O(n^2) worst, Space: O(log n) • Heap Sort: Time: O(n log n), Space: O(1) • Radix Sort: Time: O(nk), Space: O(n + k) (where k is the range of
  • 12. Time & Space Complexity (Popular Sorting and Searching Algorithms) Searching Algorithms: • Linear Search: Time: O(n), Space: O(1) • Binary Search: Time: O(log n), Space: O(1)
  • 13. Unique Paths in a Grid ALGORITH M • Use dynamic programming. • Create a 2D array dp where dp[i][j] represents the number of unique paths to cell (i, j). • Initialize the first row and column to 1. • Fill the rest of the dp table using the relation dp[i][j] = dp[i-1][j] + dp[i][j-1].
  • 14. Minimum and Maximum Element in Every Contiguous Subarray of Size k ALGORITH M • Use two deques to maintain the indices of minimum and maximum elements. • Slide the window of size k over the array and update the deques. • At each step, record the current minimum and maximum.
  • 15. Rotate the Array by K Elements ALGORITH M • Reverse the entire array. • Reverse the first k elements. • Reverse the remaining elements.
  • 16. 1:1 MOCK SESSIONS Starting at Rs. 99 Get confident Real life Experience Crack interviews Fearlessly