Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Kitty and Katty problem solution

YASH PAL, 31 July 202430 November 2025

In this HackerRank Kitty and Katty problem solution, we have given the value of N plastic blocks. Do we need to find and print the name of the winner? Assume both plays optimally.

HackerRank Kitty and Katty problem solution

Problem solution in Python.

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    T = int(input())

    for T_itr in range(T):
        n = int(input())
        if(n==1):
            print("Kitty")
        elif(n%2==0):
            print("Kitty")
        else:
            print("Katty")

Problem solution in Java.

import java.io.*;
import java.util.*;

public class KittyAndKatty {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int t = nextInt();
		while (t-- > 0) {
			int n = nextInt();
			out.println((n > 1 && n % 2 == 1) ? "Katty" : "Kitty");
		}
	}

	KittyAndKatty() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new KittyAndKatty();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Problem solution in C++.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;


int main(){
    int T;
    cin >> T;
    for(int a0 = 0; a0 < T; a0++){
        int n;
        cin >> n;
        if(n==1)
            cout<<"Kitty"<<endl;
        else if(n%2==0)
            cout<<"Kitty"<<endl;
        else
            cout<<"Katty"<<endl;
    }
    return 0;
}

Problem solution in C.

#include<stdio.h>
#include<string.h>
main()
{
    int u;
    scanf("%d",&u);
    while(u!=0)
    {
    int n;
    scanf("%d",&n);
     
        if(n==1){
          printf("Kittyn");  
        }
        else if(n%2==0){
          printf("Kittyn");   
        }
        else{
            printf("Kattyn");  
         
        }

    u--;
    }

}

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes