# Cisco Coding Questions and Answers

## Cisco Coding Questions with Solutions

This page will help you get Cisco Coding Questions and Answers asked in Online Assessment and Technical Interview of the company’s recruitment process. Other than that you will find Insights on Recruitment process of Cisco for particular job profiles.

### Steps of Cisco Recruitment Process

This Cisco Recruitment process consists of the following steps :

1. Online Assessment [Aptitude + Coding Round]
2. Technical Interview
3. HR Interview

### Insight on Cisco Online Assessment

Here are some facts related to Cisco Recruitment Test:

1. Cisco Conducts its Recruitment Test on Hackerrank.
2. On Hackerrank candidates can choose any Programming Language to solve the given Problem Statement.
3. There will be Quants, Reasoning & Computer Networks, OS, DBMS, and Basic Programming based MCQs along with Coding Questions.

### Details of  Cisco Recruitment Process

Cisco Recruitment Process starts with Online Assessment and is followed by a Technical Interview, we have given further details below :

RoundsTopicsTime
Online AssessmentAptitude + Coding Questions~ 90 Minutes
Technical InterviewDSA, OS, Computer Networks, DBMS, OOPs Concepts & other Core Subjects.~ 1.5 – 2 Hours

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Cisco Technical Test Coding Questions with Solutions

### Question 1 : Coin Game

Raman was playing a game,  he starts with x coins. Now in every step, he wins and loses and he has to get the money or pay the money as needed. He came in contact with a psychic who can see the future and the Psychic predicted the outcomes after each step. Now Raman wants to start the game with the minimum wage where he doesn’t run out of money.  Help Raman to find what money he should start with. The only rule to keep playing is not going in a credit situation.

#### Input Format:

• First line with n, number of steps in the game
• Next n lines, n integers denoting outcomes of every game. Positive means winning and negative means losing that money.

#### Output Format:

• One single integer denoting the minimum amount to start with

#### Constraints:

• Number of steps<=10^9
• -1000<=Money needed in each step<=1000

4
2
-9
15
2

7

#### Explanation:

If he starts with 7 rupees, then after steps : 7 ->9 -> 0-> 15 -> 17.

Run
#include<bits/stdc++.h>
using namespace std;

int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
int sum=0,ans=0;
for(int i=0;i<n;i++)
{
sum+=a[i];
if(sum<1)
{
sum=-sum;
ans+=sum;
sum=0;
}
}
cout<<ans<<endl;
}
Run
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];

for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int sum=0,ans=0;
for(int i=0;i<n;i++)
{
sum+=arr[i];
if(sum<1)
{
sum=-sum;
ans+=sum+1;
sum=1;
}
}
System.out.println(ans);
}
}
Run
n=int(input())
arr=[]
for i in range(n):
arr.append(int(input()))
s,a=0,0
for i in arr:
s=s+i
if(s<1):
a=a+(-1*s)
s=0
print(a)

### Question 02 : Device Name System

Problem statement: Rocky is a software engineer and he is creating his own operating system called “myFirst os”. myFirst os is a GUI (Graphical user interface) based operating system where everything is stored in files and folders. He is facing issues on  creating unique folder names for the operating system . Help rocky to create the unique folder name for it’s os.If folder name already exists in the system and integer number is added at the name to make it unique. The integer added starts with 1 and is incremented by 1 for each new request of an existing folder name. Given a list of folder names , process all requests and return an array of corresponding folder names.

#### Example

• n=5
• foldername= [‘home’ , ‘myfirst’ ,’downloads’, ‘myfirst’, ‘myfirst’]
• Foldername[0] = ‘home’ is unique.
• Foldername[1] = ‘myfirst’ is unique.
• Foldername[3] =’myfirst’ already exists in our system. So Add1 at the end of the folder name i.e foldername[3] =”myfirst1″
• Foldername[4 ]=’myfirst’ also already exists in our system.So add 2 at the end of the folder name i.e. foldername[4]=”myfirst2″.

#### Function description

• Complete the function folderNameSystem In the editor below
• folderNameSystem has the following parameters
• string foldername[n]: an array of folder name string in the order requested

#### Returns:

• String[n]:  an array of strings usernames in the order assigned

#### Constraints

•     1<=n<=10^4
•     1<=length of foldername[i]<20
•     foldername[i] contains only lowercase english letter in the range ascii[a-z]

#### Input Format:

• The first line contains an integer n , denoting the size of the array usernames Each line i of the n subsequent lines (where i<=0<=n) contains a string usernames[i] representing a username request in the order received.

• 4
• home
• first
• first

• home
• first
• first1

#### Explanation 0

•    foldername[0] = ‘home’ is unique
•    foldername[2]= ‘first’ is unique
•    foldername[3]=’first’ is already existing . so add 1 to it and it become first1
Run
#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin>>n;
vector v(n);

for(int i=0;i<n;i++) cin>>v[i];

map<string,int> m;
for(auto i:v){
if(m[i])
cout<<i<<m[i]<<endl;
else
cout<<i<<endl;
m[i]++;
}
}
Run
import java.util.*;

public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0;i<n;i++){
String str=sc.next();
if(map.containsKey(str)){
int count=map.get(str);
count = count+1;
map.put(str,count);
}
else
map.put(str,1);
}

Set s = map.entrySet();
Iterator itr = s.iterator();

while(itr.hasNext()){
Map.Entry m=(Map.Entry)itr.next();
int value=(Integer)m.getValue();
System.out.println(m.getKey());
value--;
for(int i=1;i<=value;i++){
System.out.println(m.getKey()+""+i);
value--;
}
}
}
}
Run
n=int(input())
arr = []
ans = ""
for i in range(n):
arr.append(input())
print()
for i in range(n):
if arr[:i+1].count(arr[i])>1:
ans = arr[i]+str(arr[:i+1].count(arr[i])-1)
else:
ans = arr[i]
print(ans)

### Question 3 : Coloured Zenga

Problem Statement :

Rahul is playing a game, wherein he has multiple coloured wooden blocks, stacked one above the other, his task is to remove all the wooden blocks from the stack, without letting it fall and in the minimum number of steps. He can remove one block of a colour at a time, but he can remove multiple blocks of the same colour together. Determine the minimum number of steps in which he can perform this task.

For example, if you remove [red,red] from (white,red,red,white), the resulting array is [white,white].

Note- there are only two colour blocks – red and white

Function description :

Complete the minMoves function in the provided editor. It contains the following parameters:

Parameters:

NameTypeDescription
NIntegerNo. of Wooden blocks
Array[ ]Integer ArrayArray of Blocks.

Input format :

The first line contains an integer n denoting the number of blocks. Each n line denotes the colour of the wooden block .

Constraints :
1<=n<=700
0<=a[i]<=1

Sample input 1 :

4
red
white
white
red

Sample Output 2 :

2

Explanation :

Remove [white,white] first The array will be [red,red] The remaining numbers can  be removed in one strap .

Sample Input 1:

4
white
red
white
red

Sample Output 1:

3

Sample Explanation:
0
The steps are [white,red,white,red]->[red,white,red]->[red,red]->[]. Therefore the answer is 3.

Run
#include <bits/stdc++.h>

using namespace std;
int main() {
int n;
cin >> n;

vector < string > arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];

int a = 0, b = 0;
bool start = false;
for (int i = 0; i < n; i++) {
if (arr[i] == "white") {
if (!start) {
start = true;
}
} else {
if (start) {
a++;
start = false;
}
}
}
if (start) a++;
start = false;
for (int i = 0; i < n; i++) {
if (arr[i] == "red") {
if (!start) {
start = true;
}
} else {
if (start) {
b++;
start = false;
}
}
if (start) b++;
}

cout << min(a + 1, b + 1) << endl;

return 0;
}
Run
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String arr[] = new String[n];
for (int i = 0; i < n; i++)
arr[i] = sc.next();
int a = 0, b = 0;
boolean flag = false;
for (int i = 0; i < n; i++) {
if (arr[i].equals("white")) {
if (!flag)
flag = true;
} else {
if (flag) {
a++;
flag = false;
}
}
}
if (flag)
a++;
flag = false;
for (int i = 0; i < n; i++) {
if (arr[i].equals("red")) {
if (!flag)
flag = true;
} else {
if (flag) {
b++;
flag = false;
}
}
if (flag)
b++;
}
System.out.println(Math.min(a + 1, b + 1));
}
}
Run
n = int(input())
arr = []
for i in range(n):
arr.append(input())
a, b = 0, 0
start = False
for i in range(n):
if arr[i] == "white":
if not start:
start = True
else:
if start:
a += 1
start = False
if start:
a += 1
start = False
for i in range(n):
if arr[i] == "red":
if not start:
start = True
else:
if start:
b += 1
start = False
if start:
b += 1

print(min(a + 1, b + 1))

### Question 4 :Make It Palindrome

Problem Statement  :

You’re given a string, you’ve to print additional characters needed to make that string a palindrome.

A Palindrome is a sequence of characters that has the property of reading the same in either direction.

Input :
abede
Output :
ba

Sample Input :
abcfe

Sample output :
fcba

Run
#include <bits/stdc++.h>

using namespace std;

bool Pal(string s) {
string s1 = s;
reverse(s1.begin(), s1.end());
return s1 == s;
}

int main() {
string s;
getline(cin, s);
int i;
for (i = 0; i < s.length() - 1; i++)
if (Pal(s.substr(i, s.length() - i))) break;
s = s.substr(0, i);
reverse(s.begin(), s.end());
cout << s;
}
Run
import java.util.*;
public class Main {
public static boolean isPalindrome(String str) {
char arr[] = str.toCharArray();
for (int i = 0, j = arr.length - 1; i < j; i++, j--)
if (arr[i] != arr[j])
return false;
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
String res = "";
for (int i = 0; i < str.length(); i++) {
if (isPalindrome(str.substring(i, str.length()))) {
res = str.substring(0, i);
break;
}
}
System.out.println(new StringBuilder(res).reverse());
}
}
Run
def ispalindrome(s):
return s == s[::-1]

def solve(s):
if ispalindrome(s):
return None
for i in range(len(s)):
x = s[:i][::-1]
if ispalindrome(s + x):
return x

s = input()
print(solve(s))

### Question 5 : Seating Arrangement in Exam Hall

Problem Statement  :

Semester exams are going on for university students. Examiners noticed that a group of people are trying to cheat. They marked students of that group as ‘1’ and students of another group ( who are not cheating ) as ‘0’

We can reduce cheating by not allowing students from group 1 to sit together, means no two students from group 1 can sit together. Seatings are marked using above conditions. Your task is to give the seating placement of nth possibility Possibility order from 1 to 10 is given below

[1  10  100  101  1000  1001  1010  10000  10001  10010]

Sample input :

3 → number of test cases

4

6

9

Sample output :

101

1001

10001

Explanation :

4th possibility is 101

6th possibility is 1001

9th possibility is 10001

Run
#include<bits/stdc++.h>

using namespace std;

int main() {
int n, m, Max = 0;
cin >> n;
vector < int > v(n);
vector < string > arr;
for (int i = 0; i < n; i++) { cin >> v[i];
Max = max(Max, v[i]);
}
queue < string > q;
q.push("1");
int i = 1;
arr.push_back("1");
while (!q.empty()) {
cout<<"TEST"<<endl;
string a = q.front(); q.pop();
q.push(a + "0");
arr.push_back(a + "0");
i++;
if (a[a.length() - 1] == '0') {
q.push(a + "1");
arr.push_back(a + "1");
i++;
}
if (i > Max) break;
}
for (int i = 0; i < n; i++) {
cout <<  arr[v[i] - 1] << endl;
}
}
Run
import java.util.*;
class Main {
public static void possibilities(int n) {
int c = 0;
String b = "";
for (int i = 1; n != c; i++) {
String s = Integer.toString(i, 2);
if (!s.contains("11")) {
c++;
b = s;
}
}
System.out.println(b);
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
int[] a = new int[tc];
for (int i = 0; i < tc; i++) {
a[i] = sc.nextInt();
}
for (int i = 0; i < tc; i++) {
possibilities(a[i]);
}
}
}
Run
t = int(input())
a = []
m = -1
m1 = -1
for i in range(t):
m1 = int(input())
a.append(m1)
m = max(m, m1)
k2 = 2
n = m + 1
k1 = ["0"] * (n)
k1[1] = "1"
a1 = 1
while k2 < (n): if k1[a1][-1] == "0": k1[k2] = k1[a1] + "0" k2 += 1 if k2 >= (n):
break
k1[k2] = k1[a1] + "1"
k2 += 1
if k2 >= (n):
break
a1 += 1
elif k1[a1][-1] == "1":
k1[k2] = k1[a1] + "0"
k2 += 1
if k2 >= (n):
break
a1 += 1
for i in a:
print(k1[i])

## FAQs related to Cisco Coding Questions with Solutions

##### Question 1: What is the eligibility criteria for Cisco?

Eligibility Criteria for Cisco for hiring Software Engineer is:-

• BE/B.Tech – CS/IT and circuital branches.
• Minimum 80 % or equivalent C.G.P.A in academics.
##### Question 2: How many rounds are there in Cisco Recruitment Process?

Total number of Rounds in the Cisco Recruitment Process is:-

1. Online Aptitude + Technical Test
2. Technical Interview
3. HR Interview

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others