rasmiranjanbabu
BAN USER
- 1of 1 vote
AnswersWrite a program which will bold the sub-string found in string (HTML Style).
Example: string = "HelloWorld HelloWorld" substringList = ["el", "rl"] Make it like HTML Style:- NewString = "H<b>el</b>loWo<b>rl</b>d H<b>el</b>loWo<b>rl</b>d
But things become more tedious if
- rasmiranjanbabu in United StatesExample: string = "HelloWorld HelloWorld AAAAAAABBBBBBBBBBCCCCCCC" substringList = ["el", "rl", "AAAA", "BBBBB", "BC", "BBC"]
| Report Duplicate | Flag | PURGE
Google Software Analyst Algorithm - 0of 0 votes
AnswersFind out the output. Or Correct it if something is wrong.
#include <iostream> #include<typeinfo> using namespace std; class base{ public: int a; base():a(0) {} int getA(){return a;} }; class der:public base { public: int b; der():b(1) {} int getB(){return b;} }; void display(base *obj, int ele) { for(int i = 0; i < ele; i++) { cout << (obj+i)->getA() <<endl; } } int main() { int i = 3; base arrb[i]; display(arrb, 3); der arrd[i]; display(arrd, 3); return 0; }
The output is looking like
0 0 0 0 1 0
To me the output should be
0,0,0,0,0,0 //6 0's
But, how come
1
is coming in?
- rasmiranjanbabu in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Analyst C++ - 0of 2 votes
AnswersThe "Island Count" Problem
- rasmiranjanbabu in United States
Given a 2D matrix M, filled with either 0s or 1s, count the number of islands of 1s in M.
An island is a group of adjacent values that are all 1s. Every cell in M can be adjacent to the 4 cells that are next to it on the same row or column.
Explain and code the most efficient solution possible and analyze its runtime complexity.
Example: the matrix below has 6 islands:
0 1 0 1 0
0 0 1 1 1
1 0 0 1 0
0 1 1 0 0
1 0 1 0 1| Report Duplicate | Flag | PURGE
unknown xyz Algorithm - -1of 1 vote
Answershow to handle multiple data from various applications
- rasmiranjanbabu in India| Report Duplicate | Flag | PURGE
Snapdeal Software Analyst Algorithm - 0of 0 votes
AnswersHow to find the number of static objects and dynamic objects created for a class?
Let say,class MyClass { public: }; int main() { MyClass cls;//Static Object MyClass *obj = new MyClass();//Dynamic Object ... ... //So on } void NewFun() { MyClass my; MyClass *Obj1; }
It should work for all the cases, like big or small projects
- rasmiranjanbabu in United States for Embedded| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Analyst C++ - 1of 3 votes
AnswersReverse a string without using any temporary variable.
- rasmiranjanbabu in India
Suppose {{char str[] = "Hello"; then str[] = "olleH";}}}.
I told him we can "shift H to o then o to H", similarly so on. But could able to write the code.| Report Duplicate | Flag | PURGE
HCL Software Engineer / Developer C - 0of 2 votes
AnswersSuppose a linked list (having n number of node) is given to you. You don't have the starting address. I have given you suppose address of "3rd" node.
ptr = Address of 3rd node;
Now using only ptr delete 5th node. And at the end of the program my "ptr should have the address of 3rd node". Don't use any temporary ptr and variable etc.
- rasmiranjanbabu in India| Report Duplicate | Flag | PURGE
HCL Software Engineer / Developer C# - 1of 1 vote
AnswersHow answer is coming as zero instead of garbage? Does compiler sets "0" to uninitialized variable?
- rasmiranjanbabu in India#include<stdio.h> void fun(void *p); int i; int main() { void *vptr; vptr = &i; fun(vptr); return 0; } void fun(void *p) { int **q; q = (int**)&p; printf("%d\n", **q); }
| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer C - 0of 0 votes
Answers1.
x = 5; y = 6; x = y++ + x++; y = ++y + ++x; printf("%d.....%d", x, y);
2. How function pointer works?
- rasmiranjanbabu in India
3. **p vs &(*p)
4. int a[10]; how you allocate memory for the same; should be compiler independent.| Report Duplicate | Flag | PURGE
Dover Organization Developer Program Engineer C - 0of 0 votes
AnswersYesterday, I had an interview. There they asked me when the code optimization happens? Say,
- rasmiranjanbabu in India
int abc;//Global variable
abc = 3;
if(abc == 3)
{
printf("abc will be always 3");
}
else
{
printf("This will never executed");
}
Now the question is when the optimization happens? A... At Run time B... At compile time. I answered at compile time... To me I thought, compiler checks for volatile keyword at compile time. If the variable is not declared as volatile then it optimizes the code. But, when the compiler comes to know that, this variable is never ever going to be other than 3? If it is at run-time, then when compiler comes to know that variable is never ever going to be other than 3? Because if the variable is going to be changed after this part of the code executed. Please clear my doubt| Report Duplicate | Flag | PURGE
Continental Software Engineer / Developer C
And to me here the max repeating number is "2", so output should be "2"
- rasmiranjanbabu April 12, 2017How come "5" is in the output? It is not repeated....
And why output is not sorted or First come first serve (like this "1 2 0 4 3")
arr1 = [0,1,2,3, 4,5,6,7]
arr2 = [-1, 0,1,2,3]
arr = []
def mysort(arr1, arr2):
i = 0
j = 0
while i < len(arr1) or j < len(arr2):
if i < len(arr1) and j < len(arr2):
if arr1[i] < arr2[j]:
arr.append(arr1[i])
i += 1
elif arr2[i] < arr1[j]:
arr.append(arr2[j])
j += 1
elif arr1[i] == arr2[j]:
arr.append(arr1[i])
arr.append(arr2[j])
i += 1
j += 1
elif i < len(arr1):
arr.append(arr1[i])
i += 1
elif j < len(arr2):
arr.append(arr2[j])
j += 1
return arr
print(mysort(arr1, arr2))
If at all I understood the question correctly, then here is my answer is in Python language
def camelcase(string, substring):
flag = False
arr = []
if substring[-1].islower() or substring[0].islower():
return []
#return [i for i in string for j in substring if j in i]
for i in string:
for j in substring:
if j not in i:
flag = True
break
if flag == False:
arr.append(i)
flag = False
return arr
print camelcase(['HelloMars', 'HelloWorld', 'HelloWorldMars', 'HiHo'], 'HeWorM')
def main():
l = ["a1", "a2", "a3", "a4", "a5", "b1", "b2", "b3", "b4", "b5"]
# [a1 a2 a3 a4 a5] [b1 b2 b3 b4 b5]
l1 = []
l2 = []
j = t = len(l)//2
i = 0
while i != t:
l1.append(l[i])
l2.append(l[j])
j += 1
i += 1
print(l1, l2)
l = []
for i , j in zip(l1, l2):
l.append(i)
l.append(j)
print(l)
main()
def main():
l = ["a1", "a2", "a3", "a4", "a5", "b1", "b2", "b3", "b4", "b5"]
# [a1 a2 a3 a4 a5] [b1 b2 b3 b4 b5]
l1 = []
l2 = []
j = t = len(l)//2
i = 0
while i != t:
l1.append(l[i])
l2.append(l[j])
j += 1
i += 1
print(l1, l2)
l = []
for i in range(len(l1)):
l.append(l1[i])
l.append(l2[i])
print(l)
main()
I came up with is solution
def main():
l = ["a1", "a2", "a3", "a4", "a5", "b1", "b2", "b3", "b4", "b5"]
# # [a1 a2 a3 a4 a5] [b1 b2 b3 b4 b5]
l1 = []
l2 = []
j = t = len(l)//2
i = 0
while i != t:
l1.append(l[i])
l2.append(l[j])
j += 1
i += 1
print(l1, l2)
l = []
for i in range(len(l1)):
l.append(l1[i])
l.append(l2[i])
print(l)
main()
def checkMatrix(w, h, Matrix):
flag = True
count = tmpcnt = 0
#print(Matrix)
while flag:
for i in range(0, w):
for j in range(0, h):
if (i == 0 or j == 0) or (i == w - 1 or j == h - 1):
pass#print(".")
else:
endtoend = min(Matrix[i][0], Matrix[i][h-1])
#print(endtoend, Matrix[i][0], Matrix[i][h-1])
uptodown = min(Matrix[i-1][j], Matrix[i+1][j])
leftright = min(Matrix[i][j-1], Matrix[i][j+1])
newList = [Matrix[i-1][j], Matrix[i][j-1], Matrix[i+1][j], Matrix[i][j+1]]
minval = min(newList)
if minval > Matrix[i][j]:#Matrix[i][j] < endtoend and Matrix[i][j] < uptodown:# and
Matrix[i][j] += 1
count += 1
elif endtoend > Matrix[i][j]:
#if i-1 != 0 and j-1 != 0 and i+1 != w - 1 and j-1 != h - 1:
if w < h:
if endtoend == Matrix[i][j] + 1:
Matrix[i][j] += 1
count += 1
else:
if Matrix[i-1][j] > Matrix[i][j]:
Matrix[i][j] += 1
count += 1
# if h > w and uptodown > Matrix[i][j]:
# Matrix[i][j] += 1
# count += 1
#
# else:#if w >= h and uptodown > Matrix[i][j]:
# Matrix[i][j] += 1
# count += 1
if tmpcnt == count and i == w - 1 and j == h - 1:
flag = False
tmpcnt = count
#print("\n", count, Matrix)
return count
def GetWaterLevel(input1,input2,input3):
global flag
w, h = input1, input2
count = 0
newList = []
Matrix = [input3[i:i+h] for i in range(0, len(input3), h)]
return checkMatrix(w, h, Matrix)
GetWaterLevel(4, 6, [3, 3, 4, 4, 6, 2, 3, 1, 3, 6, 1, 6, 7, 3, 1, 6, 6, 1])
GetWaterLevel(6, 3, [3, 3, 7, 3, 1, 3, 4, 3, 1, 4, 2, 6, 4, 1, 4, 2, 4, 1])
Here is my code goes in Python
# input1 n = no. of employees 4
# input2 array of n elements {2, 1, 1, 0}
# Output [4, 2, 1, 3]
# 0 [2, 1, 1, 0] [4, 2, 1, 3]
# 1 [2, 1, 1, 0] [4, 2, 1, 3]
# 2 [2, 1, 1, 0] [4, 2, 1, 3]
# 3 [2, 1, 1, 0] [4, 2, 1, 3]
import copy
def findLogic(temp, input2):
for i, (k, v) in enumerate(zip(temp, input2)):
count = 0
if i == 0:
countList = []
j = i + 1
#print(i, temp, input2)
if j in input2:
#print(i, temp, input2, input2.index(j))
for l in range(input2.index(j), -1, -1):
if l >= 0 and j <= (len(input2)-1):
if j < input2[l]:
count += 1
countList.append(count)
if countList == temp:
#print(input2)
print("{", end="")
for i in input2:
print(i, end="")
if input2.index(i) != len(input2) - 1:
print(",", end="")
print("}", end="")
return 1
def PlaceNumbs(input2, l, r, temp):
if l == r:
if findLogic(temp, input2):
return
for i in range(l, r):
input2[l], input2[i] = input2[i], input2[l]
PlaceNumbs(input2, l + 1, r, temp)
input2[l], input2[i] = input2[i], input2[l]
#def FinalOrder(n, input2):
def uniqueValue(input1,input2):
n = input1
temp = copy.deepcopy(input2)
input3 = []
for i in range(1, n+1):
input3.append(int(i))
PlaceNumbs(input3, 0, n, temp)
uniqueValue(4, [2, 1, 1, 0])
print("\n")
uniqueValue(8, [1, 2, 1, 1, 1, 1, 0, 0])
unable to understand the question. Can anybody tell the meaning of line
you are given a int[], the ith element of which represents the number of taller employees to the left of the employee with height i (where i is a 1-based index)
youtube com/watch?v=PqbcO-PijCc
- rasmiranjanbabu February 16, 2016Take A simple shape example
class Shape {
virtual void draw();
}
class rect:public shape{
void draw();
}
// Now if I want to add/register another class as circle then I can do like
class circle:public shape{
void draw();
}
I hope, I answered your question. If anyone has better answer please answer it.
- rasmiranjanbabu June 09, 2015As far as my knowledge the default value of global variable is garbage.
I think u r right. Bt in this context I have one question that,
Uninitalized global variable stored in bss segment and the initialized global variables stored in data segment. Then if the compiler autmatically sets the value of global variable to Zero. Then what is the requiremnt of bss segment. And what is the use of "static" keyword, as it also does the same, if both have declared in the same file. Look at the below example;
int i;//Compiler sets the value to Zero.
int j = 0;// Here user sets to Zero.
static int k;//Default is Zero
main()
{
printf("%d...%d...%d",i, j, k);
}
What makes the difference in the above program?
Naveen, Thanks for the answer, but if "int" is of 4 bytes then how can we allocate?
- rasmiranjanbabu August 11, 2013I hope this link may help you
tianrunhe . wordpress . com/2012/06/10/transform-one-word-into-another-by-changing-only-one-letter-at-a-time/
remove the spaces and add http
@Sarvan, I think your answer is really good. But just want some psuedo code.
Could you pls write some pseudo code?
http : // stackoverflow . com/questions/2362097/why-is-the-size-of-an-empty-class-in-c-not-zero
- rasmiranjanbabu March 03, 2013Finally See the answer
int main()
{
char *abc = "01011011001";
vector<char> def;
int zero = 0;
while(*abc != NULL)
{
if(*abc == '0')
{def.push_back(48);
abc++;}
else
{abc++;zero++;}
}
while(zero!=0)
{def.push_back(49);zero--;}
for (unsigned n=0; n<def.size(); ++n) {
cout << def.at( n ) ;//<< " ";
//printf("%c", def.at( n ));
}
cout <<"\n";
system("pause");
return 0;
}
Adding to @redbanana.blueapple answer,
You can use below code for more better understnding.
/**
I am a boy -> boy a am I
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int i, j, n, temp, temp_i, cnt;
//char *array = "Samsung";
char array[1000];
char newarr[strlen(array)];
printf("Enter The String: \n");
gets(array);
for(i = (strlen(array)-1), n = 0, j = 0; i >= 0; i--)
{
if( array[i] != ' ')
{
n++;
}
else
{
temp = n;
temp_i = i;
for(n = 0; n <= temp; n++)
{
// i = i + 1;
newarr[j++] = array[i++];
}
i = temp_i;
n = 0;
}
if(i == 0)
{
newarr[j++] = ' ';
temp = n;
temp_i = i;
for(n = 0; n <= temp; n++)
{
// i = i + 1;
newarr[j++] = array[i++];
}
i = temp_i;
n = 0;
}
//newarr[j++] = array[i];
}
newarr[j] = '\0';
cnt = 0;
for(j = 0; j <= (strlen(newarr)-1); j++)/*This is not required just do some R n D*/
{
newarr[j] = newarr[++cnt];
}
// printf("The first element is %c \n", newarr[1]);
puts(newarr);
return 0;
}
But when i replaced long int y[5] to char i[5]; and int x[5] to char x[5].
Then also the result is 15 and 15. So could you please tell me why?
To my knowledge it should print element stord in 1st bit //x[0], y[0].
Don't you think so?
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
int i, j;
char *mac_add = "ab:cd:ef:12:34:56";
char result[strlen(mac_add)];
j = 0;
for(i = 0; i <= strlen(mac_add); i++)
{
if(mac_add[i] != ':')
{
result[j++] = mac_add[i];
}
else
{
result[j++] = ',';
result[j++] = ' ';// Not required
// j++;
}
}
puts(result);
return 0;
}
According to question all values should be in ascending order and push the zero to the end...
Find the answer below
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
// printf("Hello world!\n");
int i, j, x;
int arr[7] = {1, 2, 0, 4, 0, 0, 8};
int arr1[7];
for(i = 0; i < 7; i++)
{
for(j = (i + 1); j < 7; j++)
{
if(arr[i] > arr[j])
{
x = arr[i];
arr[i] = arr[j];
arr[j] = x;
}
else
{
}
}
}
for(i = 0; i < 7; i++)
{
printf("The arr[%d] = %d \n", i, arr[i] ); // 0 0 0 1 2 4 8
}
for(i = 0, j = 0; i < 7 ; i++)
{
if(arr[i] != 0)
{
arr1[j] = (arr[i]); //<< i)/pow(2, i);
j++;
}
}
for(i = j; i < 7; i++, j++)
{
arr1[j] = 0;
}
for(i = 0; i < 7; i++)
{
printf("The arr1[%d] = %d \n", i, arr1[i] ); //1 2 4 8 0 0 0
}
return 0;
}
- rasmiranjanbabu March 27, 2018