Skip to content

Commit

Permalink
Merge pull request #6 from ratanboddu/airbnb-smallest-number
Browse files Browse the repository at this point in the history
Adding Solution for airbnb - SmallestNumber #2
  • Loading branch information
emafazillah authored Oct 31, 2020
2 parents 8c5b8e6 + fa6cb8c commit 73c2dac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Convert Roman Numerals to Decimal | Twitter | [ConvertRomanNumeralsToDecimal.jav
String Compression | Twitter | [ConvertRomanNumeralsToDecimal.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/twitter/StringCompression.java) | Done |
No Adjacent Repeating Characters | LinkedIn | [NoAdjacentRepeatingCharacters.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/linkedin/NoAdjacentRepeatingCharacters.java) | To Do |
Make the Largest Number | Uber | [MakeTheLargestNumber.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/uber/MakeTheLargestNumber.java) | Done |
Smallest Number that is not a Sum of a Subset of List | Airbnb | [SmallestNumber.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java) | To Do |
Smallest Number that is not a Sum of a Subset of List | Airbnb | [SmallestNumber.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java) | Done |
Maximum Path Sum in Binary Tree | Facebook | [MaximumPathSumInBinaryTree.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/facebook/MaximumPathSumInBinaryTree.java) | To Do |
Permutations of numbers | Facebook | [PermutationsOfNumbers.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/facebook/PermutationsOfNumbers.java) | To Do |
Longest Consecutive Sequence | Amazon | [LongestConsecutiveSequence.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/amazon/LongestConsecutiveSequence.java) | To Do |
Expand Down Expand Up @@ -209,4 +209,4 @@ Deep Copy Graph | Microsoft | [DeepCopyGraph.java](https://github.com/emafazilla
LRU Cache | Apple | [LRUCache.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/apple/LRUCache.java) | To Do |
Sorting a list with 3 unique numbers | Google | [SortingAListWith3UniqueNumbers.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/google/SortingAListWith3UniqueNumbers.java) | Done |
Find the k-th Largest Element in a List | Facebook | [FindTheKthLargestElementInAList.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/facebook/FindTheKthLargestElementInAList.java) | Done |
Palindrome Integers | Twitter | [PalindromeIntegers.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/twitter/PalindromeIntegers.java) | Done |
Palindrome Integers | Twitter | [PalindromeIntegers.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/twitter/PalindromeIntegers.java) | Done |
30 changes: 30 additions & 0 deletions src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.dailyinterviewprojava.airbnb;
import java.util.Arrays;
import java.util.Scanner;

import com.dailyinterviewprojava.util.InputUtil;

/**
*
Expand All @@ -12,5 +16,31 @@
*
*/
public class SmallestNumber {
int findSmallestNumber(int arr[], int n)
{
int res = 1; // Initialize result
for (int i = 0; i < n && arr[i] <= res; i++)
res = res + arr[i];

return res;
}

public static void main(String[] args)
{
// Input
Scanner scanner = new Scanner(System.in);
String[] inputs = InputUtil.inputArr(scanner.next());
int[] nums = InputUtil.integerArr(inputs);

// Lenth of the array
int n1 = nums.length;

// Printing Output
SmallestNumber small = new SmallestNumber();
System.out.println(small.findSmallestNumber(nums, n1));

scanner.close();

}

}

0 comments on commit 73c2dac

Please sign in to comment.