To create an empty data frame with fixed number of rows but no columns, we can use data.frame function along with the matrix function. That means we need to create a matrix without any column using matrix and save it in a data frame using data.frame function as shown in the below examples.Example1Live Demo> df1 df1Outputdata frame with 0 columns and 10 rows Example2Live Demo> df2 df2Outputdata frame with 0 columns and 100 rows Example3Live Demo> df3 df3Outputdata frame with 0 columns and 39 rows Example4Live Demo> df4 df4Outputdata frame with 0 columns and 20 rows Example5Live Demo> df5 df5Outputdata ... Read More
We are given a number N as input. Perform two operations on N and identify the count of unique numbers generated in the process. Steps will −Add 1 to numberRemove trailing zeros from the generated number, if anyIf N is 8 then numbers generated will beApplying step 1− 8 → 9 →Applying step 2− 1 → ( removed 0 from 10 )Applying step 1: 2 → 3 → 4 → 5 → 6 → 7 → 8 ( same sequence )Count of unique numbers will be 9.For ExampleInputN=21OutputCount of unique numbers that can be generated from N by adding one ... Read More
Given a sorted doubly linked list containing integer values. The goal is to find triplets whose product is equal to the given value x. If input linked list is 3−4−1−2 and x is 6 then count will be 1 (triplet (3, 1, 2) )For ExampleInputlinked list: [ 3−4−13−5−10−10−0 ] x=20OutputCount of triplets in a sorted doubly linked list whose product is equal to a given value x are: 2ExplanationTriplets will be: ( 3, 4, 13 ) and ( 10, 10, 0 )Inputlinked list: [ 4−3−1−5−2−4−2 ] x=8OutputCount of triplets in a sorted doubly linked list whose product is equal to ... Read More
Given a sorted doubly linked list containing integer values. The goal is to find triplets whose product is equal to the given value x. If input linked list is 3−4−1−2 and x is 6 then count will be 1 (triplet (3, 1, 2))For ExampleInputlinked list: [ 200−4−16−5−10−10−2 ] x=200OutputCount of triplets in a sorted doubly linked list whose product is equal to a given value x are: 3ExplanationTriplets will be: (4, 5, 10), (4, 5, 10) and (10, 10, 2)Inputlinked list: [ 4−3−1−5−2−4−2] x=12OutputCount of triplets in a sorted doubly linked list whose product is equal to a given value ... Read More
Given an array arr[] containing integer elements and an integer num. The goal is to find the average of each element arr[i] and num and print the count of the number of times that average appeared in the original array.If array arr[] is [ 5, 2, 3 ] and num is 2. Averages will be [ 3, 2, 2 ] occurrences in arr[] is [ 1, 1, 1 ]For ExampleInputarr[] = { 1, 6, 4, 3, 6, 4 } num=2Output1 2 1 0 2 1Count of occurrences of the average of array elements with a given number are − 5ExplanationThe ... Read More
Given a string str, a character and a positive integer N. The string str is repeated indefinitely. The goal is to find the count of occurrences of character in str in first N characters of repetitions.If str is “abac”, character is ch=‘b’ and N is 10.In first 10 characters of “abacabacabacabac…….” b occurs twice.Note − Take str and character ch within the same case.Let us understand with examples.For ExampleInputstr = "TPTTTT" ch = 'T' n = 12OutputCount of occurrences of a character in a repeated string are: 10ExplanationThe number of ‘T’ in str is 5. Length of str is 6. ... Read More
Given two strings str_1 and str_2. The goal is to count the number of occurrences of substring str2 in string str1 using a recursive process.A recursive function is the one which has its own call inside it’s definition.If str1 is “I know that you know that i know” str2=”know”Count of occurences is − 3Let us understand with examples.For ExampleInputstr1 = "TPisTPareTPamTP", str2 = "TP";OutputCount of occurrences of a substring recursively are: 4ExplanationThe substring TP occurs 4 times in str1.Inputstr1 = "HiHOwAReyouHiHi" str2 = "Hi"OutputCount of occurrences of a substring recursively are: 3ExplanationThe substring Hi occurs 3 times in str1.Approach used ... Read More
To use the PSCustomObject inside the Foreach Parallel loop, we first need to consider how we are using the variables inside the loop.$Out = "PowerShell" ForEach-Object -Parallel{ Write-Output "Hello.... $($using:Out)" }So let see if we can store or change a value in the $out variable.Example$Out = @() ForEach-Object -Parallel{ $using:out = "Azure" Write-Output "Hello....$($using:out) " }OutputLine | 4 | $using:out = "Azure" | ~~~~~~~~~~ | The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept | assignments, such as a ... Read More
When we simply write the Invoke-Command, it shows the output on the console.ExampleInvoke-Command -ComputerName Test1-Win2k12 -ScriptBlock {Get-Service}OutputIt shows the output along with the computer name.Now let's say you want to sort the output or you want to work with the output you need to store it. It is similar like we store the output in the variable but we can’t store the output inside the scriptblock and display it outside.$ser = @() Invoke-Command -ComputerName Test1-Win2k12 -ScriptBlock {$ser = Get-Service} Write-Output "Services output" $serYou won’t get any output of the above command because Invoke-Command is known to work on the remote computer. ... Read More
To check the logged-in Azure user account in the console using PowerShell, you can check the context of the Azure and for that Get-AZContext command is used.ExampleGet-AzContextOutputIf you are already logged in with multiple user accounts then there may be chances that there are multiple contexts available, to list all the available context, use the below command,ExampleGet-AzContext -ListAvailableOutputYou can choose the context using the Select-AZContext command.