Amazon | OA | SDE 1/2 | India, Bangalore

Problem 1
Amazon ML team is analysing some old dataset which is present in the form of unsorted array which contains both positive and negative integers. Their aim is to find the smallest positive integer missing from the dataset in O(n) time using O(1) space. Can you help them in writing code for the above requirement.

For Example:
Input: { -2, 5, 2, 3, -8, 1, -10, -5, 6 }
Output: 4

Input: { -3, -1, 1, 2, 3, 4 }
Output: 5

Ref: https://leetcode.com/problems/first-missing-positive/

.....................................................................................................................................................................................

Problem 2
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the sum of length of last 2 words (last 2 word means the last two appearing words if we loop from left to right) in the string.
If last 2 words not exist, return 0.
Note: A word is defined as a maximal substring consisting of non-space characters only.
Example:
Input: "Hello Java World"
Output: 9 (Java = 4 + World = 5)

Input: "Corona"
Output: 0 (Only one word exist)

//////// Amazons own coding platform - livecode //////

Comments (2)