Sample Problem: Electronics Shop ( HackerRank ) (Find me on HackerRank @ Handle: BishalG ) Problem Summary: In this problem, you are given two arrays of positive integer numbers of lengths n and m respectively and another positive integer b . Your task is to find out the maximum integer formed by the summation of two integer values taken from different arrays and is less than or equal to b. If there does not exist such summation print -1 . Solution Idea: Since the constraints for n and m are small ( i.e. 1 <= n, m <= 1000 ) , so this problem is very much suitable to test different variants of our solution approaches. Here, we will discuss about 3 different approaches to solve this problem progressively starting from least efficient solution to most efficient one. Approach - 1: Brute-force If we think in brute-force manner, the naive approach to solve this problem will be to try every possible pairing among these two arrays. For this, we can just it...
You are given graph N (10^5) nodes and starting node (S), You have to find min distance needed to go to all other nodes. Connections among nodes are a little bit different in the form of range type queries, which are: (1) you can open a portal from planet u to planet v with cost z. (2) you can open a portal from planet u to any planet with index in range [l, r] with cost z. (3) you can open a portal from any planet with index in range [l, r] to planet u with cost z. Idea: If we tried to make a adjacency matrix normally by traversing from l to r in (2) and (3) type of connection queries, it will surely time out. So, what we have to do is to think little bit about segmenttree representation of array. This representation allow us to make connection matrix only with LOGN adjacency nodes. So that we may proceed further. Lets build two types of segment-tree nodes , say UP segment tree , which will be used for (2) type of query and DOWN segmenttree which will be used for (3) type of ...
UVA 1734: Numbered Card ( ACM-ICPC Dhaka Regional 2015 ) Idea: The problem is asking for total numbers of subsets that can be constructed by using only numbers within 1 to N such that no two numbers contains same digit on their representation . Where, N can be as much as 1e9. So, main generalization to this problem is considering the pattern of numbers that can be included in a subset.Let us assume that 1,11,111,111,1111 are same type of numbers. Similarly, 2,22,222,2222...also 12,21,211,122,121 are of same type of numbers. So, it is easy to see that there are total 2^10 type of numbers.So, total size of subset will never be great than 2^10. So, if we calculate for each type of numbers how many are there within 1 to N. (This can be done with digit dp) Then, we may proceeds for core idea of problem. The idea is that, we can find total different subsets by DP keeping track of current position out of total 2^10 position and the mask of different digit included...
Comments
Post a Comment