Amazon Prime Video is developing a new feature called "Segmentify." This feature applies to a video with n (even) visual frames, where each frame is represented by a binary character in the array `frames`. In this format, a "0" represents a black pixel, and a "1" represents a white pixel.
Due to factors like lighting and camera angles, some frames may need horizontal or vertical flips (changing
Asked in: AMAZON
Analyze the efficiency of the following sorting algorithm by counting the number of swaps it performs:
For an array `arr` of size `n`:
1. Find the smallest pair of indices 0 โค i < j โค n-1 such that arr[i] > arr[j], where "smallest" means lexicographical ordering of pairs (i1, j1) < (i2, j2) if i1 < i2 or (i1 = i2 and j1 < j2).
2. If no such pair exists, the algorithm stops.
3. Otherwise, swa
Asked in: UBER
Given a string composed of lowercase letters within the ASCII range 'a'-'z', determine the number of substrings that consist solely of vowels, where each vowel appears at least once. The vowels are ['a', 'e', 'i', 'o', 'u']. A substring is defined as a contiguous sequence of characters within the string.
Example
s = 'aeioaexaaeuiou'
There is a substring to the left that is made of vowel
Asked in: AMAZON
Bitwise Palindromic Paths
You are given a binary matrix of size N x M where each cell contains either 0 or 1. A path from the top-left cell (0,0) to the bottom-right cell (N-1,M-1) is valid if you can only move right or down at each step.
A path is called bitwise palindromic if the sequence of bits collected along the path forms a palindrome when interpreted as a string (e.g., 0110, 1, 101).
Asked in: UBER
Minimum Time to Complete Tasks with Dependencies
You are given N tasks numbered from 0 to N-1. Each task takes 1 unit of time to complete. Some tasks depend on the completion of other tasks and can only start once all their prerequisite tasks are finished. You are given a list of dependency pairs (a, b), meaning task a must be completed before task b can start.
You have unlimited resources a
Asked in: ZOMATO
Rotten Oranges
You are given an N x M grid representing a storage area for oranges. Each cell in the grid can be:
- 0: empty cell
- 1: fresh orange
- 2: rotten orange
A rotten orange at position (i, j) spreads rot to its adjacent fresh oranges (up, down, left, right) every minute. The rotting process happens simultaneously for all rotten oranges at each time step.
Your task i
Asked in: ZOMATO
Implement a prototype for a text editor application with the following functionalities:
Command
Actions:
- ["Insert", s]: Insert the string s at the current cursor position. The cursor moves right by the length of s.
- ["Left", x]: Move the cursor x positions to the left, but not past the start of the string.
- ["Right", x]: Move the cursor x positions to the right, but not past the
Asked in: MICROSOFT
Given a string, determine how many different substrings exist that have no repeating characters. Two substrings are considered different if they have different start or end indices.
Example
s = "abac"
The substrings with no repeating characters are "a", "b", "a", "c", "ab", "ba", "ac", and "bac".
Note that "aba" and "abac" do not qualify because the character 'a' is repeated in them.
Asked in: MICROSOFT
A coding competition organized to recruit software developers includes a problem involving the bitwise-OR operation. The score of a sequence is defined as the result of the bitwise-OR operation on its elements. Given an array arr of length n, identify all possible distinct scores that can be obtained by selecting any strictly increasing subsequence from the array. Return the results sorted in asce
Asked in: MICROSOFT
Java: Social Network Interaction System
Design and implement a social media platform where users can follow and unfollow each other, post content, and receive notifications about new posts from the users they follow. You should print a message when a new user is added, when a user follows or unfollows another user, and when a user posts or receives a notification.
Complete the following meth
Asked in: STRIPE