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 :
- Online Coding Round
- Technical Interview
- HR Interview
Insight on Cisco Online Assessment
Here are some facts related to Cisco Recruitment Test:
- Cisco Conducts its Recruitment Test on Hackerrank.
- On Hackerrank candidates can choose any Programming Language to solve the given Problem Statement.
- Aptitude Based Questions may or may not be asked in Online Assessment, but Coding Questions are always asked.
- Team of 3 Members needs to be formed to participate in the Online Assessment.
- Discussion within the team is allowed, while solving the given problem statements.
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 :
Rounds | Topics | No. of Questions | Time |
---|---|---|---|
Online Assessment | Advanced Coding Questions | 3 | 1 Hour |
Prime Course Trailer
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
Sample Input:
4
2
-9
15
2
Sample Output:
7
Explanation:
If he starts with 7 rupees, then after steps : 7 ->9 -> 0-> 15 -> 17.
#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; }
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); } }
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 [2] =’downloads’ 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.
Sample case 0
- 4
- home
- download
- first
- first
Sample Output 0
- home
- download
- first
- first1
Explanation 0
- foldername[0] = ‘home’ is unique
- foldername[1]=’download’ is unique
- foldername[2]= ‘first’ is unique
- foldername[3]=’first’ is already existing . so add 1 to it and it become first1
#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]++; } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); LinkedHashMap<String, Integer> map=new LinkedHashMap<>(); 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--; } } } }
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:
Name | Type | Description |
---|---|---|
N | Integer | No. of Wooden blocks |
Array[ ] | Integer Array | Array 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.
#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; }
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)); } }
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
#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; }
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()); } }
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
#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; } }
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]); } } }
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 Cisco Coding Round Process for 2023.
- There is a Online coding assessment where students need to solve 3 Coding problems in 1 Hour.
- Students can participate in the team of 3 members and every team must have 1 leader.
- Only leader can solve the Coding problems while the other team mates can help the leader.
- All the team members need to present on a common google meet while attempting the test.
Question 1: How many team members are allowed in Cisco Online Coding Assessment?
Team of 3 candidates must be formed to participate in Cisco Online Coding Assessment.
Question 2: How much time is allotted in Cisco's Code With Cisco Coding Assessment?
1 Hour is allotted to the particular team to complete whole Online Coding Assessment.
Question 3: How many Problem Statements are given to the particular team in Code With Cisco Coding Assessment?
Total 3 Problem Statements are given to the particular team to solve in 1 Hour time Slot.
Question 4: Is discussion is allowed in Code With Cisco Coding Assessment ?
Yes, Discussion is allowed within the Team. If team members are in separate locations, they can use Google Meet to communicate with each other.
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
Login/Signup to comment