FO7's blog

By FO7, history, 3 months ago, In English

https://leetcode.com/discuss/interview-question/5846629/SquarePoint-OA-Desk-Quant/

Any ideas how to solve this problem ? some of my observations: (i) all k's are independent to each other (ii) looking for corners ?? Thanks in advance

Full text and comments »

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

By FO7, history, 16 months ago, In English

Given a undirected graph(Total No of Nodes is 1e5) .each node has its beauty .each edge has its own time travel cost .U have some finite time say m(<=100).U are at root node of graph.U have to travel those nodes and return to root .find the maximum beauty that u can collect. Idea is by knapsack .But I am facing difficulty in calculating dp states.Please confirm if it is Np-hard problem (As i correctly remember this was asked in coding test )

Thanks

Full text and comments »

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

By FO7, history, 16 months ago, In English

Given a sequence of integers ,find a subsequence of largest length such that in the subsequence adjacent elements are not equal at most k times. n<=1e3,k<=n<=1e3 .. Any Hints or ideas?

upd: Thank You everyone. Final solution:

suppose u are at index i.say p denotes index of prev elements.say given array is a ; dp[x][y]=max length when u have explored only till x index and atmost y non equla adjacent pairs.

brute force dp(O(n3)):- for(int p=0;p<i;p++) { for(int j=0;j<k;j++) {int a=-1,b=-1; if(a[i]==a[p]) a=dp[p][j]+1; else if(j>=1) b=dp[p][j-1]+1;

dp[i][j]=max{dp[i][j],a,b} }

}

Very easy to optimise: we want just max out of dp[0 ....... i-1][j] and max out of dp[0...... i-1][j-1] using map[value][j].I have tried to be accurate .Still U find some thing to be correct pls inform.

Full text and comments »

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