s = input("Enter a string: ") a = [0] * 255 for i in range(0, len(s), 2): a[ord(s[i])] += int(s[i + 1]) ans = "" for i in range(255): if a[i] != 0: ans += chr(i) ans += str(a[i]) print("Output:", ans)
question 1 in java import java.util.*; public class ibm2 { public static void main(String []args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); int ch1[]=new int[255]; for(int i=0;i
code for binary to decimal #include using namespace std; int main(){ int binary=111,decimal=0,x=0; while(binary>0){ int rem=binary%10; decimal+=pow(2,x); x++; binary=binary/10; } cout
we have to parse the value like: char key = s[i]; // The character key i++; // Move to the next character which should be the start of the number // Extract the number which may have multiple digits int value = 0; while (i < s.length() && isdigit(s[i])) { value = value * 10 + (s[i] - '0'); i++; }
s = input("Enter: ") chk_array = [0]*255 res = "" for i in range(1,len(s),2): chk_array[ord(s[i-1])] += int(s[i]) for i in range(len(chk_array)): for j in range(chk_array[i]): res += chr(i) print(res)
I gave coding assessment for back-end developer I completed Java but while writing half of the sql my time over... So can I get selected for next English round
Bhaiya 1 ka ye dekha jara s="a3b2c5a1g9c2" d={} for i in range(0,len(s),2): char=s[i] freq=int(s[i+1]) if char not in d: d[char]=freq else: d[char]+=freq res="" for char in sorted(d.keys()): res+=char res+=str(d[char]) print(res)
//program to convert decimal number to binary number import java.util.*; public class ibm3 { public static void main(String []args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int rem=0; StringBuffer sb=new StringBuffer(); while(n>0){ rem=n%2; sb.append(rem); n=n/2; } sb.reverse(); System.out.println(sb); } }
For 1st question we can use this solution : import Foundation var mainArr = ["g","2","b","4","a","2","c","5","a","1","Z","7","A","4"] var ansArr = [String]() for var i in 0..0 { ansArr.append(name) ansArr.append(String(count)) } } print("Hi:",ansArr ) print("Hello World")
Python solution using dict: import string st = input('Enter incorrectly compressed string: ') dt = {} for i in st: if i.isalpha(): dt[i] = 0 for i in range(len(st)): if st[i].isalpha(): dt[st[i]] += int(st[i+1])
print(dt) ls_keys = list(dt.keys()) ls_keys.sort() dt_sorted = {i:dt[i] for i in ls_keys} ls_sorted_keys = list(dt_sorted.keys()) ls_vals = list(dt_sorted.values()) print(dt) correct_st = '' dt_len = len(dt) print(dt_len) for i in range(dt_len): correct_st = correct_st + ls_keys[i] + str(ls_vals[i]) print(correct_st)
st = 'a3b2c4a4d6b5' l = list(st) d={} srr='' lt=[] l1=l[::2] l2 = set(l1) l3=list(l2) l3.sort() for i in l3: d[i]=l1.count(i) ll=list(d.items()) ln=len(ll)*2 for j in ll: for i in j: lt.append(i) for t in lt: srr=srr+str(t) print(srr) ##python code
//program to convert binary number to decimal number import java.util.*; public class ibm4 { public static void main(String []args){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); StringBuffer sb=new StringBuffer(s); sb.reverse(); s=new String(sb); int n=Integer.parseInt(s); int rem=0; double dec=0; int i=0; while(n>0){ rem=n%10; dec=dec+rem*Math.pow(2,i); i++; n=n/10; } int ans=(int)dec; System.out.println(ans); } }
s = input("Enter a string: ")
a = [0] * 255
for i in range(0, len(s), 2):
a[ord(s[i])] += int(s[i + 1])
ans = ""
for i in range(255):
if a[i] != 0:
ans += chr(i)
ans += str(a[i])
print("Output:", ans)
Thanks a million
question 1 in java
import java.util.*;
public class ibm2 {
public static void main(String []args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int ch1[]=new int[255];
for(int i=0;i
code for binary to decimal
#include
using namespace std;
int main(){
int binary=111,decimal=0,x=0;
while(binary>0){
int rem=binary%10;
decimal+=pow(2,x);
x++;
binary=binary/10;
}
cout
Integer.toBinaryString(64);
in Java. C++ has something similar?
Binary to decimal:
s = int(input('Enter: '))
res = 0
counter = 0
while s!=0:
res += (2**counter)*(s%10)
s = s//10
counter+=1
print("Output:", res)
What if the frequency is given in more than 1 digit? Like a5g14c6b1a12b3
Good question bhai👍
we have to parse the value like:
char key = s[i]; // The character key
i++; // Move to the next character which should be the start of the number
// Extract the number which may have multiple digits
int value = 0;
while (i < s.length() && isdigit(s[i])) {
value = value * 10 + (s[i] - '0');
i++;
}
s = input("Enter: ")
chk_array = [0]*255
res = ""
for i in range(1,len(s),2):
chk_array[ord(s[i-1])] += int(s[i])
for i in range(len(chk_array)):
for j in range(chk_array[i]):
res += chr(i)
print(res)
Hi Team, I had IBM coding round on 31st of August (ON_Campus) and questions were super huge and complex. Some required concepts from DP too.
which clg
@@20-ECE-145ShivamKumar Tier 3 college of Kolkata-
Can you please share the questions ?
Was the exam proctored? Can we refer syntax
Please tell me about the exam
** Ques-1 : JAVA Solution using single loop **
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class Test7 {
public static void main(String[] args) {
String compStr = "a3b2c5a1g9c2";
Map map = new HashMap();
for (int i = 0; i < compStr.length(); i+=2) {
if (!map.containsKey(compStr.charAt(i))) {
map.put(compStr.charAt(i), Character.getNumericValue(compStr.charAt(i+1)));
} else {
map.replace(compStr.charAt(i), map.get(compStr.charAt(i)) + Character.getNumericValue(compStr.charAt(i+1)));
}
}
String correctStr = map.entrySet().stream().map(e -> e.getKey()+""+e.getValue()).collect(Collectors.joining(""));
System.out.println(correctStr);
}
}
My personal laptop so slow...can i give hackerrank exam in wipro laptop?
Thank you sir
Kya hum javascript me code kr skte hai
I gave coding assessment for back-end developer I completed Java but while writing half of the sql my time over... So can I get selected for next English round
what was the question can u tell i am written today
Was the exam proctored? Can we refer syntax
Turner Corner
Bhaiya 1 ka ye dekha jara
s="a3b2c5a1g9c2"
d={}
for i in range(0,len(s),2):
char=s[i]
freq=int(s[i+1])
if char not in d:
d[char]=freq
else:
d[char]+=freq
res=""
for char in sorted(d.keys()):
res+=char
res+=str(d[char])
print(res)
//program to convert decimal number to binary number
import java.util.*;
public class ibm3 {
public static void main(String []args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int rem=0;
StringBuffer sb=new StringBuffer();
while(n>0){
rem=n%2;
sb.append(rem);
n=n/2;
}
sb.reverse();
System.out.println(sb);
}
}
For 1st question we can use this solution :
import Foundation
var mainArr = ["g","2","b","4","a","2","c","5","a","1","Z","7","A","4"]
var ansArr = [String]()
for var i in 0..0 {
ansArr.append(name)
ansArr.append(String(count))
}
}
print("Hi:",ansArr )
print("Hello World")
** Ques -2 : JAVA Solution **
import java.util.Scanner;
public class Test8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
sc.close();
String binNum = "";
while (num != 1) {
binNum += num % 2;
num /= 2;
}
binNum += num;
System.out.println(new StringBuilder(binNum).reverse().toString());
}
}
Good morning Sir
Good Morning
Python solution using dict:
import string
st = input('Enter incorrectly compressed string: ')
dt = {}
for i in st:
if i.isalpha():
dt[i] = 0
for i in range(len(st)):
if st[i].isalpha():
dt[st[i]] += int(st[i+1])
print(dt)
ls_keys = list(dt.keys())
ls_keys.sort()
dt_sorted = {i:dt[i] for i in ls_keys}
ls_sorted_keys = list(dt_sorted.keys())
ls_vals = list(dt_sorted.values())
print(dt)
correct_st = ''
dt_len = len(dt)
print(dt_len)
for i in range(dt_len):
correct_st = correct_st + ls_keys[i] + str(ls_vals[i])
print(correct_st)
brother dont you think this code wont work when frequency is given in more than one digit like a10b5a2c7
st = 'a3b2c4a4d6b5'
l = list(st)
d={}
srr=''
lt=[]
l1=l[::2]
l2 = set(l1)
l3=list(l2)
l3.sort()
for i in l3:
d[i]=l1.count(i)
ll=list(d.items())
ln=len(ll)*2
for j in ll:
for i in j:
lt.append(i)
for t in lt:
srr=srr+str(t)
print(srr)
##python code
//program to convert binary number to decimal number
import java.util.*;
public class ibm4 {
public static void main(String []args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
StringBuffer sb=new StringBuffer(s);
sb.reverse();
s=new String(sb);
int n=Integer.parseInt(s);
int rem=0;
double dec=0;
int i=0;
while(n>0){
rem=n%10;
dec=dec+rem*Math.pow(2,i);
i++;
n=n/10;
}
int ans=(int)dec;
System.out.println(ans);
}
}