Skip to content

rohitkumar1999/Coding-Questions-

Repository files navigation

Coding-Questions-

This repo contains some good coding problems

Users

1.Rain Water Trapping

  • Problem You are given an input array whose each element represents the height of a line towers. The width of every tower is 1. It starts raining. Water is filled between the gap of towers if possible. You need to find how much water filled between these given towers.

m4hyhpw

  • Sample Input:
    2
    6
    3 0 0 2 0 4
    12
    0 1 0 2 1 0 1 3 2 1 2 1
  • Sample Output:
    10
    6

link to the solution

2.MAXIMUM SUM PATH IN TWO ARRAYS

  • Problem You are provided two sorted arrays. You need to find the maximum length of bitonic subsequence. You need to find the sum of the maximum sum path to reach from beginning of any array to end of any of the two arrays. You can switch from one array to another array only at common elements.
    link to the problem
    -Sample Input:
    1
    8 8
    2 3 7 10 12 15 30 34
    1 5 7 8 10 15 16 19
    -Sample Output:
    122
    -Explanation:
    122 is sum of 1, 5, 7, 8, 10, 12, 15, 30, 34
    link to the solution

3.Aggressive Cows

-ProblemFarmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,…,xN (0 <= xi <= 1,000,000,000).

His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ wants to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?

link to the problem

-Sample Input:
First line contains N and C, separated by a single space, representing the total number of stalls and number of cows respectively. The next line contains N integers containing the indexes of stalls.
5 3
1 2 8 4 9

-Sample Output:
3

link to the solution

4.BOSTON NUMBER

-Problem A Boston number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1 ). The first few such numbers are 4,22 ,27 ,58 ,85 ,94 and 121 . For example, 378 = 2 × 3 × 3 × 3 × 7 is a Boston number since 3 + 7 + 8 = 2 + 3 + 3 + 3 + 7. Write a program to check whether a given integer is a Boston number.
link to the problem

-Sample Input
378
-Sample Output
1
link to the solution

5.CHEWBACCA AND NUMBER

-Problem Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.

Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

link to the solution

6.Target Sum Pair

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Approach 1: Brute Force The brute force approach is simple. Loop through each element x and find if there is another value that equals to target-x.

About

This repo contains some good coding problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •