Find 2 numbers occuring odd number of times

Leave a comment

You are given an integer array, where all numbers except for TWO numbers appear even number of times.
Find out the two numbers which appear odd number of times.

More

Positive-Negative partitioning preserving order

Leave a comment

Given an array which has n integers, you need to sort this array in a special way. The negative integers should be in the front, and the positive integers should be at the back. Also, the relative position of elements should not be changed.
eg. -1 1 3 -2 2 ans: -1 -2 1 3 2.

More

Max difference non-overlapping sub-arrays

Leave a comment

Given an array of integers. Find two disjoint contiguous sub-arrays such that the absolute difference between the sum of two sub-array is maximum.
* The sub-arrays should not overlap.

eg- [2 -1 -2 1 -4 2 8] ans – (-1 -2 1 -4) (2 8), diff = 16.

More

k-distance palindrome

Leave a comment

A k-palindrome is a string which transforms into a palindrome on removing at most k characters.
Given a string S, and an interger K, print “YES” if S is a k-palindrome; otherwise print “NO”.
Constraints:
S has at most 20,000 characters.
0<=k<=30

Sample Test Case#1:
Input – abxa 1
Output – YES
Sample Test Case#2:
Input – abdxa 1
Output – No

More

More gold coins in line of pots game

Leave a comment

Pots of gold game: Two players A & B. There are pots of gold arranged in a line, each containing some gold coins (the players can see how many coins are there in each gold pot – perfect information). They get alternating turns in which the player can pick a pot from one of the ends of the line. The winner is the player which has a higher number of coins at the end. The objective is to “maximize” the number of coins collected by A, assuming B also plays optimally. A starts the game.

The idea is to find an optimal strategy that makes A win knowing that B is playing optimally as well. How would you do that?

More

Minimum range from ‘k’ sorted lists

Leave a comment

You have k lists of sorted integers. Find the smallest range that includes at least one number from each of the k lists.

For example,
List 1: [4, 10, 15, 24, 26]
List 2: [0, 9, 12, 20]
List 3: [5, 18, 22, 30]

The smallest range here would be [20, 24] as it contains 24 from list 1, 20 from list 2, and 22 from list 3.

More

Passing varargin to another function(Matlab/Octave)

Leave a comment


Recently, I needed to work in Octave. I got stuck when I needed to pass the function argument cell array “varargin” to another function. It turns out that doing this is a little tricky and requires a little thinking to do so as the other function generates its own cell array. I found a quick and easy solution to this problem – use the wildcard “:” to index all elements of the cell array “varargin” that you need to pass on.

function [] = A(varargin)
B(varargin{:});

end

The job was done!!

Using InkPresenter in Windows Phone

Leave a comment

Microsoft SilverLight

If you are developing a windows phone silverlight applications involving drawing or paint-like functionality, free-form drawing on an image/wallpaper or signature related functionality, you would invariably be using InkPresenter Class.

Beginners may encounter slight problems here as this class is not very-well documented(if you will) and also there are not sufficient samples involving the demonstration of InkPresenter class.

If you want to get your work done without doing much research in documentation, Official SilverLight Samples is your way to go. It is the best collection of examples involving the use of silverlight applications. You can choose InkPresenter class from the left pane, test it live on the middle screen and then check out the source code available at the top.

Stroke class is used to draw curves and can be employed in many creative ways to do some interesting stuff. If you want to paint/draw over an image from user’s phone or internet, you may want to check out PhotoChooser Task.
Also, although tricky, it is possible nevertheless to save your fun work on the inkpresenter as an image(.bmp, .jpg, .png, etc.). You may then wish to go a step further and share this picture to social networks like facebook, G+ etc.
I hope I gave some ideas and helped out some Windows Phone developers via this post. If so, please let me know in the comments below. Also, I tried finding a way to draw straight lines in InkPresenter, but it turns out there is no direct way to do so. If someone has a short way to do that, please share it here.

Hello world!

1 Comment

English: Green "hello world" text.

Hello Everyone!!

A very warm welcome to my blog. Here you will find my random ramblings and some interesting stuff mostly related to me and my work. I am Koderok, your buddy here 🙂 . I love to do a lot of stuff – mostly hacking and coding, like to have good food and play a lot of games.

Feel free to contact me to discuss anything related to my posts or any other thing you feel like( either in the comments section or drop me a personal message ). I’ll see to it that you are definitely replied back 🙂

Let the fun begin !!