• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

There are N nuts and N bolts, u have to find all the pairs of nuts and bolts in minimum no. of iteration

April 27, 2015 by Dhaval Dave

With First look you think practical way of solving this question, and that is randomly taking a bolt and finding (by Looking at all nuts) perfect fit nut for it.
but does such logic to find approximate fit nut doing hit and try is possible in simple coding practice ?
No , so in order to achieve that what can be simple ways

Method 1) Brute Force Approach

Take a nut and find its pair bolt in all Bolts.
Complexity : O(n^2)

Method 2) Simple and Efficient

Sort all bolts and all nuts based upon diameter ..  All pairs will be automatically formed.
Nuts[i] <-> Bolt[i]. (as same diameter bolt and nut will fit )
But this will be inefficient as question is asked with least comparisons .
here comparisons  will increase (as You are sorting Nuts and Bolts both)
with less sorting complexity also it can be done if you use non-comparison based  methods.

Method 3)  With help of Map.

Algorithm :
1) Create a Map of  <diameter, Address of Bolt>
2) For all N nuts.
check diameter and search in map.
if diameter matches =   declare them both as pair
else print “no bolt for this nut”
3) end

With this simple algo you can find all pairs of nuts and bot in N comparisons only.

Similar Articles

Filed Under: Adobe Interview Questions, Interview Questions, problem Tagged With: Array, Hashmap

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

C++ OOPs Part2

Mirror of Tree

Find if two rectangles overlap

BFS (Breath First Search)

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Inorder and Preorder traversals of a Binary Tree given. Output the Postorder traversal of it.

CodeChef’ RRCOPY

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

Interfaces in C++ (Abstract Classes in C++)

Code Chef PRGIFT Solution

Sort Stack in place

Given Set of words or A String find whether chain is possible from these words or not

Adobe Interview Questions 8 month Exp

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

Microsoft BING Interview Experience

Print Power Set of a Set

Stickler thief

LeetCode: Container With Most Water

Reversal of LinkedList

Cisco Hiring Event 21st – 22nd Feb 2015

LeetCode : Word Search

Find an index i such that Arr [i] = i in array of n distinct integers sorted in ascending order.

Leetcode: Merge Intervals

TicTacToe Game As Asked in Flipkart

Binary Tree in Java

Trie Dictionary

Printing intermediate Integers between one element & next element of array

Word Break Problem

In Given LinkedList Divide LL in N Sub parts and delete first K nodes of each part

Top 10 Interviews Techniqes for Campus Interview in IIT NIT BITS for MTech

Copyright © 2026 · Genesis Framework · WordPress · Log in