Sum of Elements in Z Shape on Matrix in Python

Arnab Chakraborty
Updated on 05-Oct-2020 12:12:57

455 Views

Suppose we have one n x n matrix M, we have to find the sum of all elements that form a Z shape in the matrix.So, if the input is like432918256then the output will be 23, as elements are [4+3+2+1+2+5+6] = 23.To solve this, we will follow these steps −n := row count of matrixif n

Find Maximum Profit by Buying Stock Multiple Times in Python

Arnab Chakraborty
Updated on 05-Oct-2020 12:08:38

302 Views

Suppose we have a list of prices representing the stock prices of a company in chronological sequence, we have to find the maximum profit we could have made from buying and selling that stock any number of times. We have to keep in mind that we must buy before we can sell it.So, if the input is like prices = [10, 50, 30, 40, 60], then the output will be 70, as We can buy at 10, sell at 50, buy at 30, and sell at 60.To solve this, we will follow these steps −prev_price := infinityprofit := 0for each ... Read More

Find Maximum Profit by Buying Once in Stock Market Using Python

Arnab Chakraborty
Updated on 05-Oct-2020 12:07:00

1K+ Views

Suppose we have a list of prices representing the stock prices of a company in chronological sequence, we have to find the maximum profit we could have made from buying and selling that stock only once. We have to keep in mind that we must buy before we can sell it.So, if the input is like prices = [10, 12, 9, 6, 8, 12], then the output will be 6, as we can buy at 6 and sell at 12.To solve this, we will follow these steps −max_profit := 0min_stock := infinityfor each price in prices, domax_profit := maximum of ... Read More

Check If a Graph Is Bipartite in Python

Arnab Chakraborty
Updated on 05-Oct-2020 12:05:32

821 Views

Suppose we have one undirected graph, we have to check whether the graph is bipartite or not. As we know a graph is bipartite when we can split the nodes of the graph into two sets A and B such that every edge {u, v} in the graph has one node u in A and another node v in B.So, if the input is likeThen the output will be True, [0, 4] are in set A and [1, 2, 3] are in set B, and all edges are from A to B or B to A, not A to A ... Read More

Find Maximum Width of a Binary Tree in Python

Arnab Chakraborty
Updated on 05-Oct-2020 11:54:32

189 Views

Suppose we have a binary tree, we have to find the maximum width of any level in the tree. Here the width of a level is the number of nodes that can hold between the leftmost node and the rightmost node.So, if the input is like then the output will be 2To solve this, we will follow these steps−create a map d, to hold minimum and maximum values, minimum is initially infinity and maximum is 0Define a function dfs() . This will take root, pos := 0, depth := 0if root is null, then o returnd[depth, 0] = minimum of d[depth, ... Read More

Get Pagefile Settings Using PowerShell

Chirag Nagrekar
Updated on 05-Oct-2020 11:32:59

10K+ Views

Pagefile also Known as Virtual Memory file in the Windows Operating system is a very useful part of the OS. It helps to reduce the burden on the Physical memory by storing some paging file in the file call Pagefile.sys. Generally, this file in windows OS is stored in C:\ unless it is modified.You can check the Pagefile settings in the Windows GUI usingSystem Properties → Advanced → Performance → Settings → Advanced → Virtual Memory → Change.We have made a few blocks and circles in the above pagefile properties image. We will see them one by one.First, to check ... Read More

Get Hidden Files and Folders Using PowerShell

Chirag Nagrekar
Updated on 05-Oct-2020 11:29:24

13K+ Views

To get hidden files and folders using PowerShell, we need to use the Get-ChildItem command with the - Hidden or -Force parameter.The difference between the two mentioned parameters is Hidden parameter only retrieves the hidden files and folders while the Force parameter retrieves all the files and folders including Hidden, read-only and normal files and folder.For example, We have one folder named Data inside folder C:\temp and we need to retrieve it.PS C:\> Get-ChildItem C:\Temp\ -Hidden Directory: C:\Temp Mode        LastWriteTime      Length Name ----        -------------     ------ ---- d--h-       ... Read More

Remove Pagefile on Specific Drive Using PowerShell

Chirag Nagrekar
Updated on 05-Oct-2020 11:22:57

3K+ Views

In this article, we have a pagefile set on E: (System managed) and we need to remove the pagefile from E: So in the below image once we remove it, the pagefile should be “No Paging File”.To do so using PowerShell, we need to filter the pagefile on a specific drive and need to run the below code.$pagefileset = Gwmi win32_pagefilesetting | where{$_.caption -like 'E:*'} $pagefileset.Delete()You may want to reboot the server after removing pagefile.To change the above settings on the remote computer, use -ComputerName parameter in the GetWMIObject class.

Change Pagefile Settings from Custom to System Managed using PowerShell

Chirag Nagrekar
Updated on 05-Oct-2020 11:20:44

929 Views

To change the pagefile settings to system managed, we need to set InitialSize and MaximumSize parameters to 0. In the below example, we have E: has custom pagefile, not system managed and we need to convert it to the system managed.$pagefileset = Gwmi win32_pagefilesetting | where{$_.caption -like 'E:*'} $pagefileset.InitialSize = 0 $pagefileset.MaximumSize = 0 $pagefileset.Put() | Out-NullNow when you check the pagefile setting on E: it should be System managed.To change the settings on the remote computer use -ComputerName parameter in the Get-WmiObject method.

Change Pagefile Settings Using PowerShell

Chirag Nagrekar
Updated on 05-Oct-2020 11:18:47

11K+ Views

To change the pagefile settings, we will divide this into multiple sections. First, when Pagefile is automatically managed, we can’t modify the settings so we need to remove that box. In GUI that box can be unchecked in Virtual memory settings.Code to uncheck the above box.$pagefile = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges $pagefile.AutomaticManagedPagefile = $false $pagefile.put() | Out-NullSo once the above code is executed, other fields will be enabled. We now need to Customize the size of the pagefile in the below image by providing Initial and Maximum size using PowerShell.Here we have already the pagefile on the C: while on the ... Read More

Advertisements