Logo

dev-resources.site

for different kinds of informations.

Weekly Coding Questions - W3

Published at
7/23/2022
Categories
dsa
coding
interviewpreparation
leetcode
Author
the-arcade-01
Author
13 person written this
the-arcade-01
open
Weekly Coding Questions - W3

Here are this week's questions

1) Find All Duplicates in an Array

Hash Map
While traversing the array, check if the current element is present in the map or not, if its present then thats a duplicate element, push it into the ans array and continue. If not then store it into map.

One Pass & Constant Space
The idea is to use the elements as indexes and mark the positions reached by them as negative of their original value. By doing so, we determine that if we reach that position again(i.e it will be negative), then that means the element which we used as an index was a duplicate number.

2) Max Area of Island

Perform a DFS traversal and for each traversal count the no. of ones and mark the visited position zero. Then return the maximum obtained by all areas.

3) Reverse Integer

Basic reversing a integer, just check whether it exists in integer range or not.

4) Add Binary

Perform the binary addition on strings by maintaining the carry.

5) Palindrome Number

Perform the reverse operation and compare.

6) Happy Number

Perform the necessary logic.

7) Missing Number

Actual sum - array sum, will give missing number.

8) Maximum Product of Three Numbers

After sorting, last 3 digits product or first 2 digit and last digit product.

9) Power of Two

Use right shift operator(>>) to shift the number and count the ones present in it binary form. If count is equal to 1 then its a power of two.

10) Minimum Moves to Equal Array Elements

Increasing or decreasing of the elements is same. So, the idea is to decrease all the elements to zero. We can achieve this by first subtracting the elements by minimum number and then adding the sum of remaining elements.

array = [2, 3, 4]
subtract 2 (minimum no.) from all the elements
array = [0, 1, 2]
now to make the array all zero, no. of operations 
will be equal to sum of all the elements.

formula generated = sum of array - minNum * size of array
Enter fullscreen mode Exit fullscreen mode

11) Minimum Deletions to Make Array Divisible

The idea is simple, a number can divide a group of numbers when the gcd of all those numbers is divisible by that number. So, we calculate the gcd of all those numbers and then for removing the smallest number who does not divide we sort the given array and then we just check.

interviewpreparation Article's
23 articles in total
Favicon
Prepare for Interview Like a Pro with Interview Questions CLI
Favicon
NAIL YOUR NEXT JOB INTERVIEW
Favicon
5 Tools Every Developer Should Master Before Their Next Interview
Favicon
4 Ways You May Use BFS and DFS In the Real World
Favicon
AWS Api GateWay & AWS Lambda Interview Question
Favicon
Interview Coach - Diksha Arora
Favicon
Mastering the Search for Your Dream Job: 10 Essential Steps for Developers
Favicon
Jobs Interviews in Big Tech - How to Prepare?
Favicon
WHY OS and WHAT is OS :)
Favicon
The Ultimate List of Job Hunting Resources for Software Developers Part 6: Computer Science Fundamentals
Favicon
The Ultimate List of Job Hunting Resources for Software Developers Part 5: Behavior Round
Favicon
The Ultimate List of Job Hunting Resources for Software Developers Part 4: Prepare For System Design Interview
Favicon
The Ultimate List of Job Hunting Resources for Software Developers Part 3: Prepare For Coding Interview
Favicon
The Ultimate List of Job Hunting Resources for Software Developers Part 2: Apply For Jobs and Manage Your Applications
Favicon
Dreading a System Design Interview? Here Are Five Resources That Can Help🏅
Favicon
Top 10 trending github repos for JavaScript developers in this week🍎.
Favicon
Weekly Coding Questions - W3
Favicon
Top 10 trending github repos for JavaScript developers in this week😳.
Favicon
How to prepare for an interview with the founder
Favicon
Top 10 trending github repos for JavaScript developers in this week😍.
Favicon
Story of Transition to the Senior SE role
Favicon
Automate your interview schedule process
Favicon
Implementation of STACK in java.

Featured ones: