
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Nov 4, 2022, 2:20 PM EDT
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
int[] num = new int[] { 6, 5, 4, 8 }; //int[] num = new int[] { 7, 7, 7, 7 }; int[] sorted = (int[])num.Clone(); Array.Sort(sorted); int[] output = new int[4]; int idx = 0; foreach (int item in num) { output[idx] = Array.IndexOf(sorted, item); Console.Write(output[idx] + ",") ; idx++; }Note : try to improve this code once you understand logic,
All the best for your next interview in advance.
Jaya PrakashRank #1,293 · 1.3K reputationPosted Nov 5, 2022, 12:05 AM EDT
Thank you sir
Jaya PrakashRank #1,293 · 1.3K reputationPosted Nov 5, 2022, 12:07 AM EDT
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);
}
}
}