Sameer
BAN USER
- 0of 0 votes
AnswersYou are required to collect N numbers from a bag. Initially, the bag is empty. Whenever you put a number X in the bag, then the owner of the bag asks the question.
- Sameer in United States
The questions are as follows:
. What is the greatest integer that is smaller than X and present inside the bag?
. What is the smallest number that is greater than X and present inside the bag?
If you answer both the questions correctly, then you can put X inside the bag. Your task is to answers the questions that are asked by the owner of the bag. If no such numbers exist in the bag print -1.
Example:
5 (Number of elements in the bag)
1
4
2
3
7
output:
-1 -1
1 -1
1 4
2 4
4 -1| Report Duplicate | Flag | PURGE
Amazon Java Developer Data Structures - 0of 0 votes
AnswersLet's assume we have a queue named 'Demo' which receives messages from various users.
- Sameer in United States
Create a Listener which will listen to the queue 'Demo' continuously and as soon as the message is send to the queue the Listener will print out the message.
The queue is running on port : 8161
Username : admin
Password : admin| Report Duplicate | Flag | PURGE
Microsoft SDE-2 - 0of 0 votes
AnswersYou are given an array A of size N and Q queries. For each query, you are given two indices of the array L and R. The subarray generated from L to R is reversed. Your task is to determine the maximum sum of the subarrays.
- Sameer in United States
Note: After each query is solved, the array comes to its initial states.
Input format
First line: Two space-separated integers N and Q
Next line: N space-separated integers denoting the array elements.
Next
Q lines: Two space-separated integers in every line denoting the values of Li and Ri
Output format
For each query, print the required answer in a new line.
5 2
3 -1 4 2 -1
3 4
1 2
//output
8
9| Report Duplicate | Flag | PURGE
Facebook Software Developer - 0of 0 votes
AnswersComplete the puzzle which simulates generic directory structures.
- Sameer in United States
* The solution should be directory agnostic.
* Be succinct yet readable. You should not exceed more than 200 lines.
* Consider adding comments and asserts to help the understading.
* Code can be compiled with javac Directory.java
* Code should be executed as: java -ea Directory (-ea option it's to enabled the assert)
*/
/**
* change the code here.
*/
class Shell {
Shell cd(final String path) {
return this;
}
public String path() {
return "/";
}
}
public class Directory {
public static void main(String[] args) {
final Shell shell = new Shell();
assert shell.path().equals("/");
shell.cd("/");
assert shell.path().equals("/");
shell.cd("usr/..");
assert shell.path().equals("/");
shell.cd("usr").cd("local");
shell.cd("../local").cd("./");
assert shell.path().equals("/usr/local");
shell.cd("..");
assert shell.path().equals("/usr");
shell.cd("//lib///");
assert shell.path().equals("/lib");
}
}| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer - -1of 1 vote
AnswersCreate a CostDomainObject named as CostDTO (like Data transfer object or value object) with
- Sameer in United States
three attributes, costId as type String and costAmout as type BigDecimal, effectiveDate as Date.
Override equals and hashcode methods based on costId.
Create Interface CostCalculator taking above CostDTO object as 2 Arguments
1) CostDTO add(CostDTO arg1, CostDTO arg2);
2) CostDTO subtract(CostDTO arg1, CostDTO arg2);
Implement the above 2 methods. You are creating those methods to sum up or subtract cost
amounts based on costId.
Throw a checked exception when the costIds are not the same.
Mostly what I am looking for is how you test your code. This is important as you will be
re-factoring/rewriting existing code or going to enhance existing functionality. We try to do test
first development| Report Duplicate | Flag | PURGE
Bank of America Java Developer
The field in Customer_branch are cust_id and branch. What is branch is it branch_id or branch_nm.
The query according to me should be:
SELECT cust_id from Customer_Branch CB, Deposit_branch DB
LEFT JOIN Bank_Branch ON CB.branch_id = BB.Branch_id
AND CB.cust_id = DB.cust_id
Can you please elaborate the question more?
My understanding: have a table of all the products and identify them with a uniques number lets call it UIN (Unit Identification Number). Now depending on the product it can have sub-categories and sub-sub categories.
Ex: Adidas shoe :- identified by (1000)
-- can have subcategories according to color or size.
--maintained in main table named products (UIN (PK), subcategory_code (FK), description, value)
-- using the foreign key we can map the subcategory table (UINS, description, value)
Java has a very easy implementation to subscribing a queue. Using annotation
We can pull all the properties: port, hostname, virtual host, username, password in application.yml
@RabbitListener("Queue_Name")
public void listen(Message message) {
//unmarshal it to the object here and perform operations.
}
import java.util.*;
class Anagrams {
static boolean isAnagram(String a, String b) {
char c[] = a.toLowerCase().toCharArray();
char d[] = b.toLowerCase().toCharArray();
Arrays.sort(c);
Arrays.sort(d);
if(Arrays.equals(c,d)){
return true;
}
return false;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter first String: ");
String a = scan.next();
System.out.println("Enter seconf jumbled String");
String b = scan.next();
scan.close();
boolean ret = isAnagram(a, b);
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );
}
}
This problem should be solved using binary representation.
Lest assume the poison takes 2 hours to affect, the solution of 1 rat is not feasible as we will have to wait to lot of time to determine which bottle is poisoned. The simple solution is by using binary representation lets assume bottle 3rd is poisoned.
Step 1) represent all the bottles using binary representations.
Bottle 1 : 0001
Bottle 2 : 0010
Bottle 3 : 0011 (Poisoned)
Bottle 4 : 0100
Step 2) Arrange all the rats in a line.
Step 3) according to the bottles binary representation git a drop of wine to the rats for digit 1.
Rat1 Rat2 Rat3 Rat4
- - - -
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
Now according to our assumption all the rats which were given a drop from bottle 3 Should die. which would be rat 3 and rat 4.
Assume the red rats to be 1's and alive rats to be 0's which comes out to (0011) which is exactly the number of our bottle.
This approach kills 2 Rats. There's no where mentioned that we should try to keep as many rats alive possible.
import java.util.Arrays;
public class Solution {
public static void Squares(int arr[]){
int length = arr.length;
int arr1[] = new int[length];
int j=0;
for(int i=0;i<length;i++){
arr1[j] = arr[i] * arr[i];
j++;
}
Arrays.sort(arr1);
for(j=0;j<arr1.length;j++){
System.out.println(arr1[j]);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[] = {-3,-1,0,2,4};
Squares(arr);
}
}
import java.util.Scanner;
public class ApplyingCurveToGradesCC {
static void applyCurve(int arr[], int raise){
int n = arr.length;
System.out.println("Grades after applying the curve are: ");
for(int i=0;i<n;i++){
if(arr[i] >= 100){
System.out.println(arr[i]);
}
else{
arr[i] = arr[i]+raise;
if(arr[i] >= 100 ){
System.out.println("100");
}
else
System.out.println(arr[i]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("Enter the size of Grade Array : ");
int n = in.nextInt();
int Garr[] = new int[n];
System.out.println("Enter the Grades : ");
for(int i=0;i<n;i++){
Garr[i] = in.nextInt();
}
System.out.println("Enter the curve to be applied: ");
int raise = in.nextInt();
applyCurve(Garr,raise);
}
}
package com.Practice;
public class DiceGameCC {
static int sum(int arr[]){
int total =0;
int n = arr.length;
for(int i=0;i<n;i++){
total = total+arr[i];
}
return total;
}
public static int randomNum(int min, int max){
int randomNum = min + (int) (Math.random() * (max - min)+1);
//System.out.println("Num "+randomNum);
return randomNum;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Player 1 turn : ");
int player1[] = new int[10];
for(int i=0;i<10;i++){
player1[i] = randomNum(0,6);
System.out.print(player1[i] +" ");
}
System.out.println(" ");
System.out.println("Player 2 turn : ");
int player2[] = new int[10];
for(int i=0;i<10;i++){
player2[i] = randomNum(0,6);
System.out.print(player2[i]+" ");
}
System.out.println(" ");
if(sum(player1) > sum(player2)){
System.out.println("Player 1 wins with score : "+(sum(player1)));
}
else
System.out.println("Player 2 wins with Score : "+sum(player2));
}
}
import java.util.Scanner;
public class CommonStringCC {
public static void CommonAlp(String s, String s1){
char[] a = s.toCharArray();
char[] b = s1.toCharArray();
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++){
if(a[i] == b[j]){
System.out.print(a[i]);
}
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("Enter the Strings : ");
String c1 = in.next();
in.nextLine();
String c2 = in.nextLine();
CommonAlp(c1,c2);
}
}
RepHi, I’m Jamie from the Portsmouth USA and I am working as an account manager. I work for a ...
RepShastri Ji is well known hindi and tamil vashikaran specialist. He will give you effective and simple totke to control ...
Repsushiplarson, Animator at Achieve Internet
Hi, I am a creative Assistant Video Editor with experience in all aspects of video production. Working at a post-production ...
Linux command to read last 10 lines of a file :
- Sameer August 26, 2019tail -n <number_of_lines> /path/to/file