Added the given code for K-Value problem