From fa6cb8cc62bee8c973bd2d8c4b4ec94ad3a8c9ca Mon Sep 17 00:00:00 2001 From: Ratan Boddu Date: Sat, 31 Oct 2020 14:51:33 +0530 Subject: [PATCH] Adding Solution for airbnb - SmallestNumber --- README.md | 4 +-- .../airbnb/SmallestNumber.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4072884..565960e 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 | \ No newline at end of file +Palindrome Integers | Twitter | [PalindromeIntegers.java](https://github.com/emafazillah/DailyInterviewProJava/blob/master/src/main/java/com/dailyinterviewprojava/twitter/PalindromeIntegers.java) | Done | diff --git a/src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java b/src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java index 841b133..13e5a0a 100644 --- a/src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java +++ b/src/main/java/com/dailyinterviewprojava/airbnb/SmallestNumber.java @@ -1,4 +1,8 @@ package com.dailyinterviewprojava.airbnb; +import java.util.Arrays; +import java.util.Scanner; + +import com.dailyinterviewprojava.util.InputUtil; /** * @@ -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(); + + } }