annu025
 0of 0 votes
AnswerWrite a word processor that can do left and right justification for a sample input of string type.
 annu025 in United States
Here is an example:
This is a sample.This is a sample.This is a sample.
This is a sample.This is a sample.This is a sample.This is a sample.
Additional details:
* The left margin is 5 units.
* The right margin is 75 units.
* The input string is a singlespaced collection of words and punctuation.
* If the length of the word exceeds the right margin, then we must not break the word. Instead, we must print it on the next line and justify the existing line by adding more spaces to the middle of the line. Report Duplicate  Flag
Microsoft Software Engineer / Developer String Manipulation  1of 1 vote
AnswersReverse this string 1+2*320. Note: 20 must be retained as is.
 annu025 in United States
Expected output: 203*2+1 Report Duplicate  Flag
String Manipulation  0of 0 votes
AnswersYou are tasked with defining and implementing a function. as input, you are given an n x m matrix. x may appear any number of times in a matrix. your function should modify thebmatrix such that any row and column where x originally appears are completely over written with x
 annu025 in United States
For example:
    
    
   x 
x    
    
Expected output:
x   x 
x   x 
x x x x x
x x x x x
x   x  Report Duplicate  Flag
Software Engineer / Developer Matrix
Solution in Java:
public class FindElementInSortedRotatedArray {
private static int findElement(int [] input, int target){
if(input == null  input.length == 0){
return 1;
}
int start = 0;
int end = input.length  1;
int mid = (start + end)/2;
for(int i = 0; i < input.length; i++){
// check if start to mid of input array is sorted
if(input[start] <= input[mid]){
// check if target element lies between start and mid
if(input[start] <= target && target <= input[mid]){
// if target lies with start and mid, set end pointer to mid1
end = mid  1;
}
else{
start = mid + 1;
}
}
// then check if mid to end of input array is sorted
else {
if(input[mid] <= target && target <= input[end]){
// set start pointer to mid + 1
start = mid + 1;
}
else {
end = mid  1;
}
}
}
return 1;
}
public static void main(String[] args) {
{
int array[] = { 56, 58, 67, 76, 21, 32, 37, 40, 45, 49 };
findElementUsingBinarySearchTest(array, 45);
}
}
private static void findElementUsingBinarySearchTest(int[] array, int num) {
System.out.println("Element " + num + " found at = " + findElement(array, num));
}
}

annu025
February 18, 2018 My solution in Java:
import java.util.Random;
public class ShuffleDeckOfCards {
private static void shuffle(int[] input) {
int inputLength = input.length;
// class to generate random numbers
Random r = new Random();
for (int i = inputLength  1; i > 0; i) {
// Generate random index
int index = r.nextInt(i);
// swap i with randomly generated index
int temp = input[index];
input[index] = input[i];
input[i] = temp;
}
}
public static void main(String[] args) {
int[] cards = new int[52];
for (int i = 0; i < 52; i++) {
cards[i] = i + 1;
}
shuffle(cards);
}
}
// Time complexity: O(N)

annu025
February 16, 2018 public class Attempt1{
boolean[] row = new boolean[n];
boolean[] column = new boolean[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == "x") {
row[i] = true;
column[j] = true;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (row[i]  column[j]) {
matrix[i][j] = "x";
}
}
}
System.out.println("Resultant matrix: ");
printMatrix(matrix, n);
return matrix;
}
Here are my questions: 1. Is there a better way to solve this? 2. Should I consider a better data structure?
Thank you.
Open Chat in New Window
Sample input:
 annu025 March 07, 2018This is a sample.This is a sample.This is a sample.This is a sample.
This is a sample.This is a sample.This is a sample.This is a sample. This
is a sample.This is a sample.This is a sample.This is a sample.This is a
sample.