Data Structure
 Networking
 RDBMS
 Operating System
 Java
 MS Excel
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP
- Selected Reading
 - UPSC IAS Exams Notes
 - Developer's Best Practices
 - Questions and Answers
 - Effective Resume Writing
 - HR Interview Questions
 - Computer Glossary
 - Who is Who
 
Programming Articles - Page 1122 of 3366
 
			
			1K+ Views
CoinChangeTopDownApproach takes 4 parameters, n is the amount, coins array contains the coins from which the amount needs to be calculated, t is the total number of coins, dp array will store all the pre calculated values. If amount is 0 then return 0. If the value is already calculated then return from the dp array. if the value is not calculated then call the CoinChangeTopDownApproach recursively.Time complexity − O(N)Space complexity − O(N)Examplepublic class DynamicProgramming{ public int CoinChangeTopDownApproach(int n, int[] coins, int t, int[] dp){ if (n == 0){ return 0; ... Read More
 
			
			236 Views
MinimumStepstoOneBottomdownApproachtakes integer n as input. Parameter n contains the total number of elements. Initial condition checks whether n is equal to 1. If n is equal to 1 then return 0. Initialize op1, op2 and op3 to max value. If n mod 3 is equal to 0 then call MinimumStepstoOneBottomdownApproach recursively and assign it to op1, if n mod 3 is equal to 0 then call MinimumStepstoOneBottomdownApproach recursively and assign it to op2 else subtract n by 1 and call MinimumStepstoOneBottomdownApproach. Finally return the value from the dp arrayTime complexity − O(N)Space complexity − O(N)Examplepublic class DynamicProgramming{ public int ... Read More
 
			
			163 Views
MinimumStepstoOneTopdownApproach takes integer n and an integer array as input. Parameter n contains the total number of elements. Initial condition checks whether n is equal to 1. If n is equal to 1 then return 0. Initialize op1, op2 and op3 to max value . If n mod 3 is equal to 0 then call MinimumStepstoOneTopdownApproach recursively and assign it to op1 , If n mod 3 is equal to 0 then call MinimumStepstoOneTopdownApproach recursively and assign it to op2 else subtract n by 1 and call MinimumStepstoOneTopdownApproach . Finally call the Math.Min to calculate the minimum of three elements ... Read More
 
			
			559 Views
The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. The bottom-up approach first focuses on solving the smaller problems at the fundamental level and then integrating them into a whole and complete solution.Time complexity − O(N)Space complexity − O(N)Examplepublic class DynamicProgramming{ public int fibonacciBottomupApproach(int n){ int[] dpArr = new int[150]; dpArr[1] = 1; for (int i = 2; i
 
			
			857 Views
The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. The top-down approach focuses on breaking down a big problem into smaller and understandable chunks. Space complexity is O(N) because we are creating an extra array memory which is equal to the size of number.Time complexity − O(N)Space complexity − O(N)Examplepublic class DynamicProgramming{ public int fibonacciTopdownApproach(int n, int[] dpArr ){ if(n==0 || n ... Read More
 
			
			938 Views
LongestIncreaingSubsequence returns integer of the continuous subsequence from the array. The method has a for loop, which iterates and keeps the track of the numbers. the final result will have the Max calculated. Time complexity is O(N) because every element is visited once and the space complexity is O(1) because we are not making use of any storage space.Time complexity − O(N)Space complexity − O(1)Example − {2, 4, 6, 5, 8}Output − 3Examplepublic class Arrays{ public int longestIncreaingSubsequence(int[] nums){ if (nums == null || nums.Length == 0){ return -1; ... Read More
 
			
			1K+ Views
From the given string input, use the sliding window technique by having 2 pointers i and j . both i and j will point to the same character in the string. Traverse through the string and add it to the list. If the repeated character is found then remove it from the list else append to the list.Example 1Input − s = "abcabcbb"Output − 3Explanation − The answer is "abc", with the length of 3.Example 2Input − s = "bbbbb"Output − 1Explanation − The answer is "b", with the length of 1.Time complexity − O(N)Space complexity − O(N)Examplepublic class Arrays{ public int LongestSubstringWithNoRepeatingCharacters(string s){ ... Read More
 
			
			947 Views
Two strings, X and Y, are called isomorphic if all occurrences of each character in X can be replaced with another character to get Y and vice-versa. For example, consider strings ACAB and XCXY. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.Example 1Input − s = "egg", t = "add"Output − trueExample 2Input − s = "foo", t = "bar"Output − falseTime complexity − O(N)Space complexity − O(N)codepublic class Arrays{ public bool IsStringIsomorphic(string s, string t){ ... Read More
 
			
			745 Views
Create a method MoveZeros, traverse through the array and count the number of Zeros in the array. Based on the count size make all the final cells to zero. Return without processing if the array length is null or empty. The final result will be in nums Array. Time complexity is O(N) because we are traversing through the array once.Time complexity − O(N)Space complexity − O(1)Examplepublic class Arrays{ public void MoveZeros(int[] nums){ if (nums == null || nums.Length == 0){ return; } int count = 0; ... Read More
 
			
			145 Views
Pascal’s Triangle is a number pattern in the shape of a triangle. Pascal’s Triangle has many applications in mathematics and statistics, including its ability to help you calculate combinations.Each number in the triangle is the sum of the two numbers above it. For example, row 4 − it’s the sum of 3 and 3 in the row above. The very first and very last number in any row are always going to be 1.Time complexity − O(N)Space complexity − O(N)Examplepublic class Arrays{ public List GeneratePascal(int n){ List res = new List(); if (n