
Tag: Array

Upper triangular matrix
Write a Program to display the upper triangular matrix For example Solution: Continue reading Upper triangular matrix
Sum of row and column of a matrix
Write a Program to compute the sum of row and each column of a matrix For example: Solution Continue reading Sum of row and column of a matrix
Transpose of a matrix
Write a Program to find the transpose a matrix For example Solution: Continue reading Transpose of a matrix
Addition of Matrix
Write a program to calculate addition of two given matrix For example Solution: Continue reading Addition of Matrix
Rotate array elements to left
write a program to rotate array elements to left by the specified number of times. For example Solution: Continue reading Rotate array elements to left
Get Common value from two array
Write a program to get unique value from two array? For Example: Solution: Continue reading Get Common value from two array
Get Unique value from two array
Write a program to get unique value from two array. For Example: Solution: Continue reading Get Unique value from two array
Top two maximum number from Array
Write a program to Find Top two maximum number from Array. For example: Solution: Continue reading Top two maximum number from Array
Second Highest element in an array
Write a program to Find Second Highest element in an array. For example: Solution: Continue reading Second Highest element in an array
Reverse an Array Elements:
Write a program to Reverse an Array Elements without using In-build function. For example: Solution: Continue reading Reverse an Array Elements:
Move 0’s to end of array
Write a program to Move 0’s to end of arrayFor example: Solution: Continue reading Move 0’s to end of array
Find non repeated char from string.
Write a program to Find all non-repeated char from given string. For example: Solution: Continue reading Find non repeated char from string.
Length of the longest alternating sub array
Given an array of integer numbers, write a program to find the length of the longest alternating sub array from the given array. For example: Solution: Continue reading Length of the longest alternating sub array
Find Missing number in sequential array
Given an integer array with sequential number write a program to find the missing number from given array. Solution: Continue reading Find Missing number in sequential array
Sum of all sub arrays in O(n) Time
Given an array write C# program to find the sum of all the possible sub-arrays. For.e.g. int [] a = {4, 2, 1}; Output: Possible subarrays – {4}, {2}, {1}, {4, 2}, {2, 1}, {4, 2, 1} So, sum = 4+ 2+ 1 + 6 + 3 + 7 = 23 Solution Brute force approach Problem with below program is iterating over all pairs of … Continue reading Sum of all sub arrays in O(n) Time
Knapsack Problem
The knapsack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. Given weights and values of n items, put these items … Continue reading Knapsack Problem
Maximum sub array problem – Kadane’s Algorithm
Given a sequence of n real numbers A(1) … A(n), program to find a contiguous subarray with the largest sum For example, var arr = new int[] {-2, 1,-3, 4,-1, 2, 1,-5, 4 }; the contiguous sub array with the largest sum is [4, −1, 2, 1], with sum 6. Solution Solution via iterating over all array elements repeatedly, try each key elements Execute above … Continue reading Maximum sub array problem – Kadane’s Algorithm
Find all sub-array from array
Question: Find all possible subarray from given array Given an array of positive integers, Write an C# Program to find all sub arrays from an array. Answer: Subarray of an array a is a[i..j] where 0 <= i <= j < n where n is length of array. Continue reading Find all sub-array from array
Find Pair of sum in Array.
Question Given an array of unsorted array and a number, determines all pair in array in array whose sum is equivalent to the given number For example: from provided Array “arr” find all Pair who sum is 4 Answer: Logic: Get the difference between array elements and given sum number Find the difference in reaming array to get the pairs Continue reading Find Pair of sum in Array.
Sock Merchant – HackerRank Problem Solution
Question: John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. For example, there are n=7 socks with colors ar = [1,2,1,2,1,3,2]. There is one pair of color 1 and one of color 2 . There … Continue reading Sock Merchant – HackerRank Problem Solution
Array vs ArrayList
Array: An array is a collection of similar data types that can be accessed by index. Array allocates then static memory with consecutive section of memory blocks. ArrayList: ArrayList is a collection of objects of same or different types. ArrayList size can be dynamically increased or decreased as per the requirement. Here is difference table of Array vs ArrayList Array ArrayList Array stores a fixed number of elements. ArrayList is dynamic … Continue reading Array vs ArrayList
Convert Decimal to Binary (base -2)
Question: Write a C# program to convert any decimal number (base-10 (0 to 9)) into binary number (base-2 (0 or 1))? Answer: Decimal Number – Decimal number is a base 10 number because it ranges from 0 to 9, there are total 10 digits between 0 to 9. Any combination of digits is decimal number such as 223, 585, 192, 0, 7 etc. Binary … Continue reading Convert Decimal to Binary (base -2)