Amazon coding Challenge

Problem Statement

Solar power consumption has increased due to concerns over global warming. Some Amazon offices have decided to replace some of their electricity-powered bulbs with solar-powered bulbs. Here, electricity-powered means using a wired supply of electricity, and solar-powered means powered by an independent solar panel.

In one such office, the lights are arranged sequentially, represented by a binary sequence, bulbs.

  • Electricity-powered bulbs are represented by '0'.
  • Solar-powered bulbs are represented by '1'.

It is desired to have as many solar-powered bulbs as possible. However, electricity-powered bulbs are brighter than solar-powered bulbs. A bulb can only be replaced if the new solar-powered bulb is not adjacent to another solar-powered bulb.

Formally, a '0' can be replaced by a '1' if and only if it does not become adjacent to some other '1' upon replacement.

Find the maximum number of solar-powered bulbs that can be placed in the office. Note that the initial lighting may already have some adjacent solar-powered bulbs. The constraint is only for new bulbs.


Example

Example 1:
Input: bulbs = "1111110001"

Initially, there are 7 solar-powered bulbs. Only the 8th bulb can be replaced with solar. Either of the other two positions is next to a solar-powered bulb, which violates the rule. With the replacement of 1 bulb, the maximum of 8 solar-powered bulbs is achieved.

Output: 8


Function Description

Complete the function getMaxSolar in the editor below.

Function Signature:

def getMaxSolar(bulbs: str) -> int:

Input:

  • bulbs (string): A binary string that represents the initial arrangement of bulbs.

Output:

  • int: The maximum number of solar-powered bulbs after replacements under the rules.

Constraints

  • 1 <= len(bulbs) <= 100,000
  • bulbs[i] ∈ {'0', '1'}

Sample Input/Output

Sample Input 1:
Input:

bulbs = "10001"

Output:

3

Explanation:
Replace the third bulb with a solar-powered one to obtain the sequence "10101". No more replacements are possible under the rules. The maximum number of solar-powered bulbs is 3.


Problem Statement

Software developers at Amazon are developing a new library for Natural Language Processing. In one of its modules, every string needs to be preprocessed in a particular manner to find the length of its longest self-sufficient proper substring.

A self-sufficient proper substring is one where:

  1. The substring is not the entire string s.
  2. No letter that occurs inside the substring also occurs outside the substring.

Given the string fullString of length n, find the length of its longest self-sufficient proper substring. If none exists, return 0.


Example

Input:
fullString = "amazonservices"

Explanation:

SubstringLengthIs self-sufficient?Remarks
amazon6YesNo letter occurs both inside and outside the substring
services8YesNo letter occurs both inside and outside the substring
azonse6No'a' occurs outside the substring too
zonservices11YesLongest substring where no letter occurs both inside and outside

Output:
11


Function Description

Complete the function findLongestLength in the editor below.

Function Signature:

def findLongestLength(fullString: str) -> int:

Input:

  • fullString (string): The string to analyze.

Output:

  • int: The length of the longest self-sufficient proper substring.

Constraints

  • 1 <= n <= 10^5
  • fullString consists of lowercase English characters.

Sample Input/Output

Sample Input 1:
Input:

fullString = "abadgdg"

Output:

4

Explanation:
The two proper self-sufficient substrings are "aba" and "dgdg". The longest has a length of 4.


我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *