Minimum Subset Sum Difference | Dynamic Problem. Hello guys, Today we will solve an existing problem which is Minimum Subset Sum Difference. This is a DP based problem. In this question, we have given an array which contains some elements and we have to find the minimum difference of subsets. Example: arr[ ]={1,2,7}; The minimum difference of this question is 4. How? Explanation: In this question, we have to find 2 subsets which sum is equal to the sum of the whole array and the difference of 2 subsets is minimum. The subsets of the given array are {1,2},{7} because the sum of these 2 subsets is 10 and it is equal to the sum of a given array which is also 10 and the difference of these 2 arrays is minimum. Solution: I take a fixed array element or value of the n. You can take input in runtime. int n=3; int a[]={1,2,7,8}; int sum=0; for(int i=0;i<a.length;i++) { sum+=a[i]; } boolean[][] t=new boolean[n+1][sum+1]; ArrayList<Integer> ar=new ArrayList<Integer>()
Posts
Subset Sum Problem | Dynamic Problem Hello Guys, Today we will solve a very interesting problem which is Subset Sum Problem. This is a DP based problem. In this question, you have one array which contains some element and the total sum is given to you. You have to find a subset which is equal to a given sum. You have to print output True or False. Example: arr[ ]={2,3,7,8,10}; sum=11; We have to find the subset which is equal to the given sum which is 11. Solution: I take a fixed array element or value of the sum. You can take input in runtime. int n=5; int a[]={2,3,7,8,10}; //Array elements int sum=11; //Given Sum //create a 2D boolean array with size of n+1 and sum+1 boolean[][] t=new boolean[n+1][sum+1]; for(int i=0;i<n+1;i++) { for(int j=0;j<sum+1;j++) { if(i==0&&j==0) { t[i][j]=true; } else if(i==0) { t[i][j]=false; } else if(j==0) { t[i][j]=true;
Caesar Cipher HackerRank Solution In Java. Hello Programmers, Today I will give you the solution of hackerrank problem which is Caesar Cipher. In this problem, we need to shifts each letter by a number of letters. Question: Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b and c. For example, the given cleartext s= " middle-Outz" and the alphabet is rotated by k=2 . The encrypted string is okffng-Qwvb. Example: Original alphabet: abcdefghijklmnopqrstuvwxyz Alphabet rotated +3: defghijklmnopqrstuvwxyzabc Solution: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution {
Super Reduced String Hackerrank Solution In Java. Hello Programmers, Today we will solve an easy hackerrank problem which is Super Reduced String with java. Question: Steve has a string of lowercase characters in a range ascii[‘a’..’z’] . He wants to reduce the string to its shortest length by doing a series of operations. In each operation, he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string 'aab' could be shortened to ' b' in one operation. Steve’s task is to delete as many characters as possible using this method and print the resulting string. If the final string is empty, print Empty String. Function Description Complete the superReducedString function in the editor below. It should return the super-reduced string or Empty String if the final string is empty. superReducedString has the following parameter(s): s : a string to reduce Input Format A single string, s. Constraints Output Format If the final st
Youtube Launch Shorts Beta Version In India. Recently Youtube launch beta version in India. We can say it is Tik Tok alternative or youtube played the smart game after Tik Tok ban. It is beneficial for those creators who have their own youtube channel or do thinking to open a new youtube channel. Tik Tokers also have a chance to come on this platform. If you have already used TikTok before then it is simple to you and you can easily move on shorts. You can adopt shorts easily. Those creators who have already youtube channel and want to join shorts. Firstly I am clearing that it is a beta version and beta version may be some lack of feature. But after some time youtube will back with some new feature, new editing tools, new filter or maybe some advanced tools which are beyond our thinking. Youtube not disclose the criteria of monetizing. I tell you my guess that maybe there will be no compulsion to one thousand subscribers and 4 thousand watch time. One more interesting thing is that
Top 4 Programming Language For Back-End Development. Hello Programmers, Today I will tell you top 4 programming language for back-end development which used worldwide for back-end development. Every programmer has there own opinion and choice for back-end language but today I will tell you top 4 programming language which is mostly used and mostly liked programming language by programmers. Firstly I will tell you what is back-end Development? Backend development is the process of developing a database that holds all the necessary information, an application programming interface (API) that communicates user requests with the database and outputs to the frontend as dictated by the user request. According to stack overflow's annual developer survey python has picked up popularity and JavaScript and Go hold the second and third position in the survey. Among rapidly growing programming languages, Go has seen an increase in demand. 1) Python:- Python is a high-level language whic