## Directi Interview Question for SDE-2s

• 0

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````function ij(A, B) {
"use strict"
memo = []
for (i = 0; i < A.length; i++) {
for (j = i+1; j < B.length; j++) {
if (A[i] > B[j]) {
memo.push("" + (i +1) + "," + (j +1))
}
}
}
var memo
, i
, j
return memo
}
console.log(ij([1, 2, 3, 4], [5, 6, 2, 1]))``````

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````import sys
a=[int(x) for x in sys.stdin.readline().split('')]
b=[int(x) for x in sys.stdin.readline().split('')]
l=[]
for i in range(0,len(a)):
for j in range(i+1,len(b)):
if a[i]>b[j]:
l.append((a[i],b[j]));
print l``````

Comment hidden because of low score. Click to expand.
1
of 1 vote

+1 for doing it in `go`

Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in C#

``````public int[,] Pairs(int[] arrayOne, int[] arrayTwo)
{
List<int> list = new List<int>();
for (int i = 0; i < arrayOne.Length; i++)
{
for (int j = i + 1; j < arrayTwo.Length; j++)
{
if (arrayOne[i] > arrayTwo[j])
{
}
}
}
int listLenght = list.Count / 2;
int[,] returnArray = new int[listLenght / 2, 2];
for (int i = 0; i < listLenght; i += 2)
{
returnArray[i / 2, 0] = list[2 * i];
returnArray[i / 2, 1] = list[(2 * i) + 1];
}
return returnArray;
}``````

Comment hidden because of low score. Click to expand.
0

I've misread the question
replace
"arrayOne[i] with i" and "arrayTwo[j] with j"

Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in javascript.

{{
function solve(A, B) {
var ret = [];
for (var j = 0; j <= B.length; j++) {
for (var i = 0; (i < j && i < A.length); i++) {
if (A[i] < B[j]) {
ret.push({
i: i,
j: j
});
}
}
}
return ret;
}
}}

Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in javascript.

{{
function solve(A, B) {
var ret = [];
for (var j = 0; j <= B.length; j++) {
for (var i = 0; (i < j && i < A.length); i++) {
if (A[i] < B[j]) {
ret.push({
i: i,
j: j
});
}
}
}
return ret;
}
}}

Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in javascript.

``````function solve(A, B) {
var ret = [];
for (var j = 0; j <= B.length; j++) {
for (var i = 0; (i < j && i < A.length); i++) {
if (A[i] < B[j]) {
ret.push({
i: i,
j: j
});
}
}
}
return ret;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in java :

``````public class PairMatch {

public static String [][] PairFind(int a[],int b[])
{
String c[][]=new String[a.length+b.length][a.length+b.length];

for(int i=0;i<a.length;i++)
{

for(int j=i+1;j<b.length;j++)
{

if(a[i]>b[j])
{
c[i][j]=""+i+","+j;

}
}
}
return c;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

solution in java

``````public class Greater {

public static void main(String[] args) {

int a[]={10,02,30,51,45,89,12};
int b[]={35,20,15,46,89,74,5};
for (int i = 0; i < a.length; i++) {

for (int j = 0; j < b.length; j++) {
{
if(a[i]>b[j]&&i<j)
{
System.out.println(i+" "+j);

}
}

}

}
}

}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static void main(String[] args) {

int[] arr1 = { 1 ,6,4,2,6,3};
int[] arr2 = {5,8,3,9,6,2};

for(int i=0;i<arr1.length;i++) {

for(int j = i+1;j<arr2.length;j++) {

if(arr1[i]<arr2[j])
System.out.println("("+i+","+j+")");
}
}
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

all of the i*j solutions are nice but if you sort the lists storing (index, value) you can then run a binary search to find where in the first array the value is smaller.

Nice thing about this is that now the solutions can build on each other.

Comment hidden because of low score. Click to expand.
0

Actually you can't because we also need to check i<j for that. After sorting A[i]<B[j] condition can be checked by using 2 pointer method but i<j won't be in sequence.
Presently we have i<j in sequence(in sorted order) and A[i]<B[j].
Sorting both brings us to square 1 with an overhead of (nlogn+mlogm)

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public HashMap<Integer, Integer> Compare(int A[], int B[])	{
HashMap<Integer, Integer> pairs = new HashMap<Integer, Integer>();
for(int i=0; i<A.length; i++)	{
for(int j=1; j<B.length; j++)	{
if(A[i]>B[j])	{
pairs.put(A[i], A[j]);
}
}
}
return pairs;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
int main()
{
int a[] = {1,2,3,55,6,4,2,1,6,7,9};
int b[] = {1,4,22,5,6,7,8,9,0,5,3};
int n = sizeof(a)/sizeof(a);
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i < j && a[i]>b[j])
cout<<"("<<i<<","<<j<<")"<<endl;
}
}

return 0;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

using binary indexed tree would be the most efficient to solve this

Comment hidden because of low score. Click to expand.
0
of 0 vote

using binary indexed tree would be the most efficient to solve this

Comment hidden because of low score. Click to expand.
0
of 0 vote

using binary indexed tree would be the most efficient to solve this

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static ArrayList<String> count(int[] a, int[] b){
ArrayList<String> list = new ArrayList<String>();
for(int i=0; i<a.length; i++){
for(int j=i+1; j<b.length; j++){
if(a[i]>b[j])
}
}
return list;
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.