Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE KINDLY GIVE ANSWER IN PYTHON PROGRAMMING WITH SCREENSHOT OF OUTPUT AND PROPER CODE OF 2 SEPARATE QUESTIONS. Q.1 : Q.2 : Given an array
PLEASE KINDLY GIVE ANSWER IN PYTHON PROGRAMMING WITH SCREENSHOT OF OUTPUT AND PROPER CODE OF 2 SEPARATE QUESTIONS.
Q.1 :
Q.2 :
Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0,1 , and 2 to represent the color red, white, and blue, respectively. You must solve this problem without using the library's sort function. Example 1: Input:nums=[2,0,2,1,1,0]Output:[0,0,1,1,2,2] Example 2: Input:nums=[2,0,1]Output:[0,1,2] Constraints: - n== nums. length - 1=n=300 - nums [i] is either 0,1 , or 2 . Follow up: Could you come up with a one-pass algorithm using only constant extra space? You are given an array of strings products and a string searchWord. Design a system that suggests at most three product names from products after each character of searchword is typed. Suggested products should have common prefix with searchWord. If there are more than three products with a common prefix return the three lexicographically minimums products. Return a list of lists of the suggested products after each character of searchword is typed. Example 1: Input: products = ["mobile", "mouse", "moneypot", "monitor", "mousepad"], searchWord = "mouse" Output: [ ["mobile", "moneypot", "monitor"], ["mobile", "moneypot", "monitor"], ["mouse", "mousepad"], ["mouse", "mousepad"], ["mouse", "mousepad"] ] Explanation: products sorted lexicographically = ["mobile", "moneypot", "monitor", "mouse", "mousepad"] After typing m and mo all products match and we show user ["mobile", "moneypot", "monitor"] After typing mou, mous and mouse the system suggests ["mouse", "mousepad"] Example 2: Input: products = ["havana"], searchword = "havana" Output: [["havana"], ["havana"], ["havana"], ["havana"], ["havana"], ["havana"]] Example 3: Input: products =[ "bags", "baggage", "banner", "box", "cloths"], searchword = "bags" Constraints: - 1 products. length =1000 - 1 products[i]. length
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started