
please help me with these questions i got rejected in the first round i am unable to solve them

please help me with these questions i got rejected in the first round i am unable to solve them
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajanikant HawaldarPosted Nov 4, 2022, 6:20 PM
input nums =>6,5,4,8
sorted nums =>4,5,6,8
indexes of sorted nums =>0,1,2,3
Clone input nums to sorted nums array thean sort sorted nums, here input nums first number is 6, in sorted nums you have to find index of 6 that is 2. Next input nums is 5, find index of 5 in sorted nums that is 1, Next inpit nums is 4, find index of 4 in
sorted nums that is 0, Next input nums is 8, find index of 8 in sorted nums that is 3 so output is 2,1,0,3
same process need will be applied for any input nums example, 7,7,7,7
Note : try to improve this code once you understand logic,
All the best for your next interview in advance.
Jaya PrakashPosted Nov 5, 2022, 4:07 AM
This is my logic
static void Main(string[] args)
{
Console.WriteLine("Enter array size");
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
int i, j; int count = 0;
Console.WriteLine("enter element into array");
for (i = 0; i < size; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < arr.Length; i++)
{
for (j = arr.Length - 1; j >= 0; j--)
{
if (arr[j] < arr[i])
{
count++;
}
Console.WriteLine("smaller than the" + arr[i] + "are" + count);
}
}
}
Jaya PrakashPosted Nov 5, 2022, 4:05 AM
Thank you sir