Skip to content

Stack Overflow API: Get answer

Gets a Stack Overflow question and its best answers, from a question link or a plain-word search. A search picks the most relevant answered question. The accepted answer comes first, then answers by score.

stackoverflow.com (opens in a new tab)Version 1ReadNo sign-inVerified Nov 2, 2026

Unofficial. Not affiliated with or endorsed by Stack Overflow.

Inputs

Values from the run on Oct 23, 2026, shown under Output.

Question, requiredquestion

A Stack Overflow question link or the question in plain words, e.g. how do I reverse a list in Python?

https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array

Max Answers optionalmax_answers

Number of answers to return, e.g. 3 (up to 10).

3

Whole number from 1 to 10. Default 3.

Output

From a run on Oct 23, 2026, shortened for this page.
{  "tags": [    "java",    "c++",    "performance"  ],  "answers": [    {      "date": "2012-06-27",      "link": "https://stackoverflow.com/a/11227902",      "score": 35296,      "author": "Mysticial",      "accepted": true,      "answer_text": "You are a victim of branch prediction fail.\n\nWhat is Branch Prediction?\n\nConsider a railroad junction:\n\nImage showing a railroad junction\nImage by Mecanismo, via Wikimedia Commons. Used under the CC-By-SA 3.0 license.\n\nNow for the sake of argument, suppose this is back in the 1800s - before long-dis…"    },    {      "date": "2012-06-27",      "link": "https://stackoverflow.com/a/11227877",      "score": 4767,      "author": "Daniel Fischer",      "accepted": false,      "answer_text": "Branch prediction.\n\nWith a sorted array, the condition data[c] >= 128 is first false for a streak of values, then becomes true for all later values. That's easy to predict. With an unsorted array, you pay for the branching cost."    },    {      "date": "2012-06-28",      "link": "https://stackoverflow.com/a/11237235",      "score": 3860,      "author": "WiSaGaN",      "accepted": false,      "answer_text": "The reason why performance improves drastically when the data is sorted is that the branch prediction penalty is removed, as explained beautifully in Mysticial's answer.\n\nNow, if we look at the code\n\n```\nif (data[c] >= 128)\n    sum += data[c];\n```\n\nwe can find that the meaning of this particular if.…"    }  ],  "question_link": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array",  "question_text": "In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster:\n\n```\n#include <algorithm>\n#include <ctime>\n#include <iostream>\n\nint main()\n{\n    // Generate data\n    const unsigned arraySize = 32768;\n    int data[arraySize];\n\n    for (unsigned c = 0; c < arraySize; ++…",  "question_title": "Why is conditional processing of a sorted array faster than of an unsorted array?"}
Price
1 credit per completed run (1¢ with pay as you go); failed runs are free.
Method
stackoverflow.com/get_answer
Returns
question title, text, link, tags, answers (text, score, accepted, author, date, link)

Use it from your agent

Give your agent this line. It reads SKILL.md, gets a Fous API key and connects the Fous MCP server. Its run then takes the method stackoverflow.com/get_answer with the inputs above.

Ask your agent

  • How do I reverse a list in Python without using reverse()?
  • Find the top accepted answer for why does my JavaScript promise return undefined
  • Show me the best answers for merge two sorted arrays in Java
  • Get the top 2 answers for git push rejected non-fast-forward error on stackoverflow.com
  • What is the most upvoted answer about SQL joins versus subqueries performance?
  • Finds Stack Overflow programming questions matching plain-language search words, optionally filtered by tag and answer status, with a chosen sort order.

    stackoverflow.com/search_questions
  • Gets a Hacker News story and its comments in the order shown on the site. The story can be given as a discussion link or as words from its title. Deleted and flagged comments are left out.

    news.ycombinator.com/get_discussion
  • Lists current Hacker News stories in rank order from the top, newest, best, Ask HN, Show HN or jobs list.

    news.ycombinator.com/list_front_page
  • Finds public Reddit posts by topic, optionally in one community, for a time window and sort order. Returns up to 100 posts in Reddit search order with score, comment count, text and link.

    reddit.com/search_posts
  • Searches Hacker News stories or comments by words, date range and sort order. Comments include their parent story's website link when one exists; text-only stories have no website link.

    news.ycombinator.com/search_stories
  • Finds a place on Google Maps by name and location and returns its public reviews in the chosen order.

    google.com/get_place_reviews
  • Searches public Bluesky posts for words, optionally ordered by latest or top and filtered by date, author or language. Search indexing may lag behind new posts.

    bsky.app/search_posts
  • Finds a Substack newsletter by name or web address and returns its latest public posts with dates, authors, access level and engagement counts.

    substack.com/list_newsletter_posts