codenote's blog

By codenote, history, 8 days ago, In English,

What is good approach to merge sorted files. I have around 10k files of size 1-2 mb and want to merge them in single sorted file.

Read more »

 
 
 
 
  • Vote: I like it  
  • -2
  • Vote: I do not like it  

By codenote, history, 2 weeks ago, In English,

I want to know different problem solving techniques and algorithms.
can anyone suggest me a good source , i know about "spoj" but read some bad review about it on quora
Is spoj good to learn different approach and algorithms ?
If any other source helped you than please tell.I don't want to waste time on adhoc problems.
Note: I know that many people ask such question and i read them also but still i have doubts so posted

Read more »

 
 
 
 
  • Vote: I like it  
  • -4
  • Vote: I do not like it  

By codenote, history, 4 weeks ago, In English,

In this problem you are given "x" amount of money in currency "s" and you want to maximise the amount in "m" steps to currency "f". cost matrix is given for transfer rate. Sounds similar to finding number of ways to reach from one node to another in k steps. So the answer to problem is (s,f) value of mth power of given cost matrix (exchange rate matrix). we need to modify matrix multiplication accordingly to get maximum cost.

code

But we want ans%mod , this mod will ruin my multiplication of matrix. I will not get maximum. Editorial suggest to use power of primes , can someone please explain that.
Problem Link

Read more »

 
 
 
 
  • Vote: I like it  
  • +5
  • Vote: I do not like it  

By codenote, history, 7 weeks ago, In English,

Your task is to find total number strings of length N consisting of {X,Y} with the following condition
a) It does not have leading "X" letter.
b) It does not contain P consecutive "X" letters.
N<10^4 and P<11
I am unable to form recurrence of this dp problem. can someone please explain the recurrence in an easy way.
I was thinking about dp[i][j] as number of strings of length i ending with j 'X' , but not able to come up with transition.
Thanks.

Read more »

Tags #dp
 
 
 
 
  • Vote: I like it  
  • -5
  • Vote: I do not like it  

By codenote, history, 3 months ago, In English,

How to solve this problem using binary search.
Problem Statement :
You are given an array A of N integers in nondecreasing order. Remove K integers such that the maximum difference between two consecutive elements is minimized.
​​Problem Link
solution using binary search (I am not getting its intuition). ​​

Read more »

 
 
 
 
  • Vote: I like it  
  • +5
  • Vote: I do not like it  

By codenote, history, 4 months ago, In English,

Today i was solving Ktree and i came with this solution. This solution gave me TLE. This is most obvious solution which anyone can think and code. Now i don't see any repetitive states in this solution to memoize .Am i missing something ? Or if i am going wrong then please tell your recursive approach.

#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9+7;
typedef long long ll;
#define mp make_pair
#define pb push_back
ll n,k,d;
ll solve(ll sum,ll seen)
{
	if(sum==n and seen==1)
		return 1;
	if(sum>n  or (sum==n and !seen) )
		return 0;

	ll ans=0;
	for(int i=1;i<=k;i++)
	{
		if(i>=d)
			seen=1;

		ans+=solve(sum+i,seen);
	}
	return ans;
}
int main()
{
	ios_base:: sync_with_stdio(false); cin.tie(0);
	// freopen ("inp","r",stdin);
	// freopen ("out","w",stdout);
	cin>>n>>k>>d;
	cout<<solve(0,0);
	return 0;
}

Read more »

 
 
 
 
  • Vote: I like it  
  • -7
  • Vote: I do not like it