Found 26504 Articles for Server Side Programming

Find array using different XORs of elements in groups of size 4 in Java

Sunidhi Bansal
Updated on 05-Nov-2021 06:03:24

181 Views

We are given with an integer array of size N(size of multiple 4) and we have to perform Xclusive OR operation on the array such that input[1- 4] resembles utility_arr[1- 4] and the conditions of computing is If arr[1 – 4] = {a1, a2, a3, a4} then q[1 – 4] = {a1 ⊕ a2 ⊕ a3, a1 ⊕ a2 ⊕ a4, a1 ⊕ a3 ⊕ a4, a2 ⊕ a3 ⊕ a4}Let us see various input output scenarios for this -In − int[] input = { 5, 2, 3, 4 };Out − Result after XOR operation 4 3 2 5Explanation −An Exclusive-OR gate's output ... Read More

Change the decimal point of every value in an R data frame column.

Nizamuddin Siddiqui
Updated on 05-Nov-2021 05:54:26

4K+ Views

To change the decimal point of every value in an R data frame column, we can use round function.For Example, if we have a data frame called df that contains a column say X and we want to have each value with 3 decimal places then we can use the below command −df$X

Why Output of mean of normal random variable created using rnorm equals to 10 is not 10 in manual calculation with R?

Nizamuddin Siddiqui
Updated on 05-Nov-2021 05:49:19

93 Views

When we find the mean of normal random variable which is created with rnorm(“sample_size”, 10) is not 10 because rnorm will create a random variable hence mean will be changed but as we increase the sample size the mean will become closer to 10.Check out the Examples given below to understand the variation in the Outputs as the sample size increases.ExampleThe variation in the Outputs of mean of normal random variable created by using rnorm as the sample size increases is explained below −mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(100, mean=10)) mean(rnorm(1000, mean=10)) mean(rnorm(1000, ... Read More

Maximum subarray sum after dividing array into subarrays based on the given queries in Java

Sunidhi Bansal
Updated on 05-Nov-2021 06:04:04

334 Views

We are given two integer arrays, one having the elements which are computed and other having split points which are required to split the array for making subset and we have to calculate the sum of each subset in every split and return the maximum subset sum.Let us understand with example:-Input − int arr[] = int arr[] = { 9, 4, 5, 6, 7 } int splitPoints[] = { 0, 2, 3, 1 };Output − Maximum subarray sum after each split [22, 13, 9, 9]Explanation − Here we are breaking the array according to their split points and obtaining the maximum subset sum ... Read More

Meet in the middle in Java

Sunidhi Bansal
Updated on 05-Nov-2021 05:34:40

386 Views

We are provided with an array and a sum value; the problem statement is to calculate the maximum subset sum which does not exceed the given sum value. We cannot apply the brute force approach here because the structure of the given array is not the same as the divide and conquer approach.Let us see various input output scenarios for this -Let us understand with exampleInput − long arr[] = { 21, 1, 2, 45, 9, 8 } long given_Sum = 12Output −The maximum sum subset having sum less than or equal to the given sum-->12Explanation −The array is split into a set ... Read More

Maximize the total profit of all the persons X in Java

Sunidhi Bansal
Updated on 05-Nov-2021 05:27:21

363 Views

We are given 5 Integer variables Num, P1, P2, profit_P1, profit_P2 and the task is to maximize the profit and from all the natural numbers in the range of [1, Num]. The approach here is that if a positive number is divisible by P1 the profit increases by profit_P1 and similarly if if the number in the range is divisible by P2 the profit margin of profit_P2 increases. Also, the profit from a positive integer can be added at most once.Let us understand with example:-Input − int num = 4, P1 = 6, P2 = 2, profit_P1 = 8, profit_P2 = ... Read More

Merge K sorted linked lists in Java

Sunidhi Bansal
Updated on 05-Nov-2021 05:20:42

788 Views

We are given a K number of linked lists of variable sizes which are sorted in their sequence and we have to merge the list into a resultant list in such a way that the resultant array is sorted in order and the resultant array is printed as the output to the user.Let us understand with example:-Input −int k = 3;list[0] = new Node(11);list[0].next = new Node(15);list[0].next.next = new Node(17);list[1] = new Node(2);list[1].next = new Node(3);list[1].next.next = new Node(26);list[1].next.next.next = new Node(39);list[2] = new Node(4);list[2].next = new Node(8);list[2].next.next = new Node(10);Output −The merged list is-->2>> 3>> 4>> 8>> 10>> 11>> 15>> 17>> ... Read More

Minimum number of bombs in Java

Sunidhi Bansal
Updated on 05-Nov-2021 05:12:36

259 Views

The problem statement here is to kill the goons in the rooms of a building with minimum number of bombings. The rooms are labelled as 1 to n. The goons are injured by the first bombing attack and die in the second. When the rooms are bombed the goons rush to the nearest room in the building specially the neighboring room. We must calculate the number of bombing it is required to bomb the rooms in order to kill all the goons in the building.Let us understand with exampleInput − int number of rooms = 3Output −Total Bombings required42 1 3 2Explanation − ... Read More

Merge k sorted arrays in Java

Sunidhi Bansal
Updated on 05-Nov-2021 05:07:13

725 Views

We are given an ‘n’ number of arrays, let's say we take three arrays i.e. arr1[], arr2[] and arr3[] of integer type. The task is to merge all the given integer arrays in such a manner that the resultant array is sorted in the runtime only.Let us understand with exampleInput −Inta[]={21, 22, 23, 24};int b[ ] ={28, 31, 35}Output −int resultant[ ]={21, 22, 23, 24, 28, 31, 35}.Explanation − The array elements are compared before they are added and added according to their suitable position in the resultant array.Input −inta[]={1, 3, 5, 7, 9, 11, 13};int b[ ] ={14, 16, 18}int c[ ] ={19, ... Read More

Find the missing numbers in a sequence in R data frame column.

Nizamuddin Siddiqui
Updated on 03-Nov-2021 10:13:49

1K+ Views

To find the missing numbers in a sequence in R data frame column, we can use setdiff function.For Example, if we have a data frame called df that contains a column say X and we want to check which values between 1 to 20 are missing in this column then we can use the below command −setdiff(1:20,df$X)Example 1Following snippet creates a sample data frame −x

Advertisements