Minimum Flips for Alternating Values in Python

Arnab Chakraborty
Updated on 22-Dec-2020 06:22:54

421 Views

Suppose we have a binary string s. Now suppose we can take some prefix of s and move it to the back. then, find the minimum number of characters that need to be flipped such that there will be no consecutive characters of the same value.So, if the input is like s = "10010101111", then the output will be 2, as we can take prefix "10", then move it to back so string is "01010111110" then flip 3rd and 5th bit from right to 0 ("01010101010").To solve this, we will follow these steps −ans := size of SN := size ... Read More

Count Minimum K-Length Sublist to Make All Items Zero in Python

Arnab Chakraborty
Updated on 22-Dec-2020 06:20:49

122 Views

Suppose we have a list of numbers called nums that stored 0s and 1s. We have another value k.Now consider there is an operation where we flip a sublist of length k such that all 1s will be 0s and all 0s will be 1s. We have to find the minimum number of operations required to change nums into all 1s to 0s. If we cannot change it return -1.So, if the input is like nums = [1, 1, 1, 0, 0, 1, 1, 1], k = 3, then the output will be 2, as we can flip the first ... Read More

Find Minimum Radius to Light Up All Houses on a Street in Python

Arnab Chakraborty
Updated on 22-Dec-2020 06:18:26

697 Views

Suppose we have a list of numbers called nums that are representing position of houses on a 1-dimensional line. Now consider we have 3 street lights that we can put anywhere on the line and a light at position x lights up all houses in range [x - r, x + r], inclusive. We have to find the smallest r required to light up all houses.So, if the input is like nums = [4, 5, 6, 7], then the output will be 0.5, as we can place the lamps on 4.5, 5.5 and 6.5 so r = 0.5. So these ... Read More

Find Minimum String Size That Contains Given Substring in Python

Arnab Chakraborty
Updated on 21-Dec-2020 14:08:50

410 Views

Suppose we have two strings s and t, we have to find the size of a minimum substring in s that contains all the characters of t. If there is no such substring exists then return -1.So, if the input is like s = "thegrumpywizardmakes" t = "wake", then the output will be 10, as the shortest substring that contains "wake" is "wizardmake" (length of 10).To solve this, we will follow these steps −counter := frequency of each character in bstart := 0min_subs := infrem := count of distinct characters in bfor end in range 0 to size of a, ... Read More

Install PowerShell Module

Chirag Nagrekar
Updated on 18-Dec-2020 12:28:03

933 Views

There are two methods to install PowerShell modules. Online and Offline.Online MethodThis method is just like downloading the online package through Yum in the Unix system.We first need to search the package available on the internet using the Find-Module command. You can use the wildcard character if you don’t know the full module name. All the packages are downloaded from PowerShell Gallery (https://www.powershellgallery.com/).For example, if you want a Vmware PowerCLI module and you don’t know the full module name then just use the part of the name inside the Wildcard character(*).Find-Module *vmware* | Select Name, Version, RepositoryName       ... Read More

Explain JSON Format in PowerShell

Chirag Nagrekar
Updated on 18-Dec-2020 09:07:54

1K+ Views

Javascript Object Notation (JSON) is the light-weight structure which is easy to read by human and simple to parse and understand by machine. Although the name contains the Javascript, both Javascript and JSON are different and they have syntax and structure is different as well.You can get more information about JSONhttps://www.json.org/json-en.htmlIts basic structure is Key-Value pair but both are separated by a colon ‘:’. It has an almost similar structure as a hashtable, PSCustomObjecct. For example, {    "Name": "Albert Don" }If you have multiple Key-Value pairs, you can separate them with a comma. For example, {    "Name": "Albert ... Read More

Write Comment-Based Help in PowerShell

Chirag Nagrekar
Updated on 18-Dec-2020 09:03:39

548 Views

In PowerShell when you create a complex script or function then it should be essential to create help for the end-users to easily understand your script functionality. Writing comment-based help or XML-based help, at the end is similar to Get-Help syntax for cmdlets or function which is the online version of help.For Example, Just open the PowerShell console and run the command below.Get-Help Get-WmiObjectAnd you can see the various help sections in the output like NAME, SYNOPSIS, SYNTAX, DESCRIPTION, PARAMETER, LINK. These are called Keywords. We can include all of them in the script of function manually to get the ... Read More

Find Maximum Points from Removals in Python

Arnab Chakraborty
Updated on 15-Dec-2020 13:16:35

265 Views

Suppose we are provided with a list of positive numbers. Now, here we can remove any contiguous sub list of some length t with the same value and get points t * t. One condition is to be considered, that we can perform this any number of times until the list is empty. So we have to determine the maximum number of points we can get.So, if the input is like nums = [4, 4, 6, 4, 4], then the output will be 17.For the output, we can first remove the 6 which has length 1 and yields 1 * ... Read More

Find Largest K-Divisible Subsequence Sum in Python

Arnab Chakraborty
Updated on 15-Dec-2020 13:14:03

431 Views

Suppose we are given a list of non−negative numbers, and a positive value k. We have to find the maximum sum subsequence of numbers such that the sum is divisible by k.So, if the input is like, nums = [4, 6, 8, 2], k = 2, then the output will be 20.The sum of the whole array is 20, which is divisible by 2.To solve this, we will follow these steps −numsSum := sum of the values in input list numsremainder := numsSum mod kif remainder is same as 0, thenreturn numsSumsort the list numsfor each number combination tpl in ... Read More

Find Longest Subsequence with Element Difference at Most K in Python

Arnab Chakraborty
Updated on 15-Dec-2020 13:12:14

478 Views

Suppose we are given a list of numbers and another value k. This time our task is to find the length of the longest subsequence where the absolute difference between every adjacent element is at most k.So, if the input is like nums = [5, 6, 2, 1, −6, 0, −1, k = 4, then the output will be 6.To solve this, we will follow these steps −Define a function update() . This will take i, xi := i + nwhile i is non−zero, dosegtree[i] := maximum of segtree[i], xi := i / 2Define a function query() . This will ... Read More

Advertisements