Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:29:15+00:00 2026-05-31T03:29:15+00:00

I have a dictionary like so – public static Dictionary<int, List<int>> pegMap = new

  • 0

I have a dictionary like so –

public static Dictionary<int, List<int>> pegMap = new Dictionary<int, List<int>>();

Now I have populated the dictionary like say –

Key: 1 => Value: [3,2]
Key: 2 => Value: []
Key: 3 => Value: [6,7]

Now I want to find the key which has the highest value in the list.

Like in this case the the lambda should return 3 which denotes the key-value pair where key is 3 because the number 7 is present in the list in the dictionary where key happens to be 3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:29:17+00:00Added an answer on May 31, 2026 at 3:29 am

    Its a bit hacky but should work.

    var dict = new Dictionary<int, List<int>>();
    
        dict.Add(1, new List<int>() { 1, 2 });
        dict.Add(2, new List<int>() { 4, 5 });
        dict.Add(3, new List<int>() { 1, 7 });
    
        var max = dict.Select(x => new { Key = x.Key, Value = x.Value.Max() }).OrderByDescending(x => x.Value).First().Key;  
    // returns 3
            // Other sample input 
            dict.Add(1, new List<int>() { 1, 2 });
            dict.Add(2, new List<int>() { 4, 7 });
            dict.Add(3, new List<int>() { 1, 2 });
            // returns 2
            dict.Add(1, new List<int>() { 1, 2 });
            dict.Add(2, new List<int>() { 4, 7 });
            dict.Add(3, new List<int>() { 1, 7 });
            // returns 2
            dict.Add(1, new List<int>() { 1,10 });
            dict.Add(2, new List<int>() { 4, 7 });
            dict.Add(3, new List<int>() { 1, 7 });
            // returns 1
    

    Edit: to the smallest value in the list with the largest value:

     var min_value_in_maxList = dict.Select(x => new { Key = x.Key, ValueMax = x.Value.Max(), ValueMin = x.Value.Min() }).OrderByDescending(x => x.ValueMax).First().ValueMin;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary declared like this. public static Dictionary<int?, List<int?>> pegMap = new
I have a dictionary like the follow: public Dictionary<int, SpawnList> spawnEntities = new Dictionary<int,
Say I have the following dictionary like so: public static Dictionary<Type, string> nullableTypeToStringMap =
Does VBA have dictionary structure? Like key<>value array?
I have a dictionary like the following. Key value pairs or username:name d =
I have a Dictionary(TKey, TValue) like Dictionary<int, ArrayList> Deduction_Employees = new Dictionary<int, ArrayList>(); and
I have a dictionary that goes like this: typedef struct dictNode { int key;
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
I have passed to template dictionary parameters like parameters={ 'value':'some_value', 'style':{} } and inside
I have a python dictionary of type defaultdict(list) This dictionary is something like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.