Domanda di colloquio di Mindstix Software Labs

1. Reverse character array without affecting special character in single loop. 2. given 2 character array S1 , S2 and 1 empty array S3. Populate S 3by interleaving character from S1 and S2

Risposte di colloquio

Anonimo

19 ago 2019

public class demo2 { public static void main(String[] args) { int a[] = new int[] {3,2,2,2,2,2,2,2,2,2,2}; int a1[] = new int[] {22,99,34,35,56,78}; int a2[] = new int[a.length+a1.length]; int n=a.length,a3[]=null; if(a1.length!=a.length) { a3 = a.length>a1.length?a:a1; n = a.length>a1.length?a1.length:a.length; } int i=0,j=0,k=0; for(i=0;i

56

Anonimo

30 ago 2019

//Soloution to problem 1 in Python 3 stir = input() newStr = "" i=0 j=len(stir)-1 while(i

37

Anonimo

28 dic 2020

public class PopulateIn3rdArray { public static void main (String[] args) { char[] ch1 = {'1', '3', '5', '7', '9'}; char[] ch2 = {'2', '4', '6', '8', '0'}; char[] ch3 = new char[ch1.length + ch2.length]; int a = 0, b = 0; for(int i = 0; i < ch3.length;) { ch3[i++] = ch1[a++]; // if(i < ch3.length) ch3[i++] = ch2[b++]; } System.out.println(ch3); } }

7

Anonimo

17 feb 2020

isAlphanumeric = ch => { return (ch >= "a" && ch = "A" && ch { let arr = ["a", ",", "b", "$", "c"]; for (let i = 0, k = arr.length - 1; i++, k--; i < arr.length) { if (this.isAlphanumeric(arr[i]) && this.isAlphanumeric(arr[k])) { let temp = arr[k]; arr[k] = arr[i]; arr[i] = temp; } } console.log(arr); };

Anonimo

6 set 2019

// C++ program to reverse a string // with special characters #include using namespace std; // Returns true if x is an aplhabatic // character, false otherwise bool isAlphabet(char x) { return ( (x >= 'A' && x = 'a' && x <= 'z') ); } void reverse(char str[]) { // Initialize left and right pointers int r = strlen(str) - 1, l = 0; // Traverse string from both ends until // 'l' and 'r' while (l < r) { // Ignore special characters if (!isAlphabet(str[l])) l++; else if(!isAlphabet(str[r])) r--; else // Both str[l] and str[r] are not spacial { swap(str[l], str[r]); l++; r--; } } } // Driver code int main() { char str[] = "a!!!b.c.d,e'f,ghi"; cout << "Input string: " << str << endl; reverse(str); cout << "Output string: " << str << endl; return 0; }

3