instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a function that reduces an array of numbers to a single number. The reduction operation should be the sum of all the numbers in the array. The input array will always contain at least one number.
Example:
Input: [2, 4, 6, 8, 10]
Output: 30
Proposed Difficulty Increase:
In addition to handling the case where the... | codefeedback |
Write a PHP script that creates a MySQL database table with three fields: "ID" (auto-increment), "name" (unique and alphanumeric), and "age" (between 18 and 100 inclusive). The script should also check if the table already exists before creating it, and handle any potential errors or exceptions that may occur during th... | codefeedback |
Implement a functional programming paradigm in Python that includes the following features:
1. Higher-order functions: Create at least five higher-order functions that take in other functions as arguments or return functions as results.
2. Pure functions: Implement at least eight pure functions that do not have any s... | codefeedback |
Re-implement the Fibonacci sequence in Python. The function should take an integer `n` as input and return the `n`th number in the Fibonacci sequence.
The Fibonacci sequence is defined as follows:
- The 0th number is 0.
- The 1st number is 1.
- Each subsequent number is the sum of the two preceding numbers.
The funct... | codefeedback |
Write a JavaScript function to check if a number is in the Fibonacci sequence. Additionally, handle edge cases where the input number is negative or zero by returning an appropriate error message. The function should also handle input numbers that are very large, such as those exceeding the maximum value that can be re... | codefeedback |
Write an SQL query to find the top 5 customers who have made the most purchases in a given month, sorted by the total amount spent. | codefeedback |
Why is it important to understand and analyze the algorithmic complexity of a solution? Provide a brief explanation and discuss its relevance in the context of developing efficient software applications. Additionally, provide an example of a real-world problem where analyzing algorithmic complexity was crucial in devel... | codefeedback |
Given a dataframe with integers and strings, write a function that adds a new column that contains the results of a calculation between two columns, where the calculation is performed only if the value in column A is greater than the value in column B. The calculation to be performed is concatenating the value in colum... | codefeedback |
Design an efficient algorithm for finding the frequency of occurrence of each vowel in a given string. The input string may contain uppercase and lowercase letters and can have a maximum length of 10^6 characters. Additionally, you are not allowed to use any built-in functions or libraries for string manipulation or re... | codefeedback |
Given an array of integers, remove the duplicate elements and sort the remaining elements in descending order. If the input array is empty or contains only one element, return the original array.
[9, 4, 6, 9, 4, 8, 2] | codefeedback |
Given a data table, write a function to select the columns. The function should also allow the user to specify a condition to filter the rows based on a given column and value. The selected columns should be returned as a new data table. The function should handle the case where the specified column does not exist in t... | codefeedback |
Generate code to return a fibonacci sequence up to n elements. However, the code should not use recursion or the golden ratio formula to calculate the fibonacci sequence. The code should use an iterative approach to generate the sequence. Additionally, the code should use a dynamic programming technique to optimize the... | codefeedback |
Design a GUI app to welcome the user and output a message. Additionally, implement a functionality that allows the user to input their name and display a personalized welcome message. The app should also have a feature that allows the user to select their preferred language for the welcome message, with options includi... | codefeedback |
Deduce whether the following code is a valid Java statement:
Create a Java program that prompts the user to enter a number and assigns that number to a variable named "num". Print whether the entered value is odd or even. Additionally, check if the entered number is a multiple of 3 and print a message stating that as ... | codefeedback |
Given a string, write a code that checks it for palindrome in O(1) space complexity and O(n) time complexity. Additionally, the code should only use bitwise operations for string manipulation.
str = "abba" | codefeedback |
Retrieve data from a collection in a MongoDB database, where each document contains multiple nested fields, and display the result in ascending order based on a specific field. The nested fields must be accessed and compared during the sorting process. Additionally, you must implement a custom sorting algorithm instead... | codefeedback |
Define a function that takes a string as input and returns true if it is a valid IPv6 address, and false otherwise.
ip_str = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
Note: IPv6 addresses are represented as eight groups of four hexadecimal digits, separated by colons. Each group can be abbreviated by using double col... | codefeedback |
Given a list of integers, output the number of distinct elements in the list. Each element in the list will be between 1 and 100 (inclusive). The input list may contain up to 10^6 elements.
Example:
Input: [1, 2, 3, 4, 5, 2, 4]
Output: 5 | codefeedback |
Write a query to return the distinct first names of all users in the database, sorted in alphabetical order. Each user document in the database has the following fields: `firstName`, `lastName`, `email`, `age`. | codefeedback |
Print out the sum of the squares of prime numbers from the following range, where each prime number should be multiplied by 3 before adding to the sum. The program should also exclude the numbers 2 and 3 from the calculation.
range(1,20) | codefeedback |
Generate a query using SQL to filter all values greater than 30 and less than 50 from a table, ordered in descending order. Additionally, calculate the sum of all filtered values and return it as a separate column in the result set. | codefeedback |
Create a C++ function to determine the number of inversions in an array. An inversion occurs when two elements in the array are out of order, i.e., if i < j but arr[i] > arr[j]. The array can contain duplicate elements. The function should return the count of inversions along with the indexes of each inverted pair. | codefeedback |
Create an algorithm that computes the sum of the maximum K (given) digits in a given array. The array may contain negative numbers and zero values. If K is greater than the length of the array, return -1.
Erroneous Reference Code:
```python
def compute_sum_of_max_digits(arr, K):
if K > len(arr):
return -1... | codefeedback |
Create a class that implements a polygon using an array of Point objects. The polygon should support the following operations:
1. Calculate the perimeter of the polygon.
2. Calculate the area of the polygon.
3. Check if a given point lies inside the polygon.
4. Check if a given point lies on the boundary of the polygo... | codefeedback |
Write a Python code to find the top k largest numbers in a list, where k is a given positive integer. The list can contain duplicates and can have a length of up to 10^6 elements. The code should have a time complexity of O(n) and should not use any built-in sorting functions or libraries. List: [2, 9, 12, 45, 10, 20, ... | codefeedback |
Create a logic using Python that checks if a string contains only alphabetical characters and has a length of at least 5 characters. Additionally, the logic should also check if the string contains at least one uppercase letter, one lowercase letter, and one digit. The logic should return True if all these conditions a... | codefeedback |
Write a function that reverses a string in place without using any additional data structures. The function should have a time complexity of O(n) and a space complexity of O(1).
In addition to reversing the string, the function should also remove all duplicate characters from the input string. The resulting reversed s... | codefeedback |
Perform a binary search on the following list of integers, but ensure that the search algorithm also returns the index of the found element in addition to the element itself. Additionally, the search algorithm should handle duplicate elements in the list and return the index of the first occurrence of the found element... | codefeedback |
Create a RESTful API endpoint that fetches user details from an external API and stores them in a relational database. The endpoint should only be accessible by authenticated users with the role of "admin". The API call should include the username and password as parameters, and the user details should be validated and... | codefeedback |
Calculate the conditional probability of an event occurring, given the following probability of each outcome, with the additional constraint that the sum of the probabilities of all outcomes must be equal to 1. You must implement the calculation using a recursive function. | codefeedback |
Create a one line solution in Python to remove all vowels from a string, but the solution should not use any built-in string manipulation functions or methods such as replace() or translate(). Additionally, the solution should have a time complexity of O(n), where n is the length of the input string. | codefeedback |
Report the number of unique words in the following text, excluding any words that contain the letter 'a' and have more than 5 characters. Additionally, the program should sort the unique words in descending order of their length, and in case of a tie, sort them alphabetically. This is a sample text. | codefeedback |
Construct a Java method to convert a string to its equivalent title case format. The string should contain a maximum of 100 characters and may include special characters. Additionally, the method should ignore the following words when converting to title case: "the", "a", "an".
Title case format means that the first ... | codefeedback |
Generate a program in Java to find the mean, median, and mode of n numbers. The program should have a time complexity of O(nlogn) and a space complexity of O(n).
Additionally, the program should handle negative numbers and floating-point numbers.
To calculate the mean, sum all the numbers and divide by the total coun... | codefeedback |
Write a regular expression that matches all prime numbers within a given string. Additionally, the regular expression should ignore any numbers that are divisible by 2 or 3. | codefeedback |
Sort a list of positive integers into two smaller lists, one with prime numbers and one with composite numbers. Additionally, the prime numbers list should be sorted in ascending order and the composite numbers list should be sorted in descending order.
[4, 2, 5, 9, 11, 8] | codefeedback |
Write HTML and CSS code to display the following table, ensuring that each table cell is highlighted with a different background color and the table is styled with CSS. Additionally, ensure that the table has a fixed header and scrollable body, with the header remaining fixed at the top while scrolling. | codefeedback |
Create a function in Python to return the approximate value of the tangent of an angle in degrees, without using the math module or any built-in trigonometric functions. The function should take two arguments, the angle in degrees and the number of terms to use in the Taylor series approximation. The function should re... | codefeedback |
What is the result of x = 2 and y = 3 in this function, f(x,y) = (x + y)^3 + x^2 + y^2? | codefeedback |
Find the length of the longest common subsequence in the following two strings, considering that a subsequence is defined as a sequence that is obtained by deleting some elements from the original sequence, but maintaining the order of the remaining elements. Additionally, the solution should have a time complexity of ... | codefeedback |
Explain the concept of memory leak in C++ and provide an example code that demonstrates a memory leak situation. Additionally, explain the potential consequences of memory leaks and how they can be avoided in C++ programming. | codefeedback |
Create an array of 15 random floats in Python between 0 and 1, ensuring that the sum of all the floats in the array is greater than 10 and the average is less than 0.5. Additionally, ensure that no two consecutive elements in the array have a difference greater than 0.2. | codefeedback |
Consider a deterministic finite automaton (DFA) with N states and M symbols in its input alphabet. Write a program to determine the set of reachable, non-reachable, and partially reachable states in the DFA.
Input:
- N: an integer representing the number of states in the DFA (1 ≤ N ≤ 10^5)
- M: an integer representing... | codefeedback |
Generate a list of all the prime numbers in the range from 0 to the given number n, but exclude any prime numbers that contain the digit 5. The solution should have a time complexity of O(n log(log n)). | codefeedback |
Create a function to normalize a given pandas dataframe by scaling all values between 0 and 1, while also rounding the values to the nearest two decimal places. Additionally, the function should handle the following scenarios:
1. If the dataframe contains any missing values, raise a custom exception called "MissingVal... | codefeedback |
Create a CSS selector to select every 5th element with a specific class on a page, and apply a different background color to each selected element. Additionally, ensure that the selected elements have a fade-in animation effect when the page loads. | codefeedback |
Create an algorithm in Python to combine two sorted lists into a single sorted list. The resulting list should not contain any duplicate elements.
list1 = [3, 5, 7, 9]
list2 = [1, 2, 4, 6, 8]
Your algorithm should be able to handle lists of any length and size, including edge cases where one or both lists are empty.
... | codefeedback |
Remove all HTML tags from a string, but also remove any content inside the tags. Additionally, convert all HTML entities to their corresponding characters. Finally, ensure that the output string is sorted alphabetically and each word is capitalized.
Input: "<h1>Hello & <strong>World</strong></h1>"
Expected Output: ... | codefeedback |
Make an API call to retrieve the latest news headlines for the world, but exclude any headlines containing specific keywords such as "politics", "entertainment", or "sports". Additionally, the API response should be sorted in descending order based on the number of shares or views each headline has received. | codefeedback |
Design a function in Python to calculate the Fibonacci sequence up to a particular number, but also implement error handling for the following specific cases:
1. Handle negative input by raising a custom exception called "NegativeInputError".
2. Handle non-integer input by raising a custom exception called "NonIntegerI... | codefeedback |
Read a line of input from the user, which should contain only lowercase letters and spaces, and print the number of vowels in the line. Additionally, you should ignore any vowels that appear after a consonant and before another vowel. | codefeedback |
Find the third smallest element in an array of positive integers, where the array size is greater than or equal to 10 and less than or equal to 100. The array may contain duplicate elements. | codefeedback |
Find the highest common factor of two numbers within the range of 1 to 100, where both numbers are positive integers and are not equal to each other. Additionally, the program should be able to handle cases where the two numbers are very large (up to 10^9) efficiently.
#Reasoning Steps#
1. Ask the user to input two p... | codefeedback |
Design a function in Java to output the same string in reverse order, while also converting all uppercase letters to lowercase and vice versa, and removing any digits from the string. String: 'Hello World! 123' | codefeedback |
Print all possible combination and permutations with length 4 for a given array.
[1, 2, 3, 4]
In addition to printing all possible combinations and permutations, also calculate the sum of each combination and permutation and print the combinations and permutations in descending order based on their sums.
Furthermore... | codefeedback |
Write a Python code to calculate the number of unique combinations of three digits from 0 to 9, where the sum of the three digits is equal to 15. Additionally, each digit can only be used once in a combination and the combination must be in ascending order. | codefeedback |
Write a query in SQL to show all the details of the customers with age greater than 30 and their total purchase amount. The total purchase amount should be calculated by summing the purchase amount for each customer. Display the result in descending order of the total purchase amount. Only display customers who have ma... | codefeedback |
Write an SQL query to return rows from the "Animals" table and sorted in ascending order based on three columns: "type", "age", and "name". Only include rows where the "type" column is not equal to "reptile", the "age" column is greater than 1, and the "name" column starts with the letter 'A'. The result should be limi... | codefeedback |
Design a code in C# to check if the input number is prime or not. The code should also print all the prime numbers within a given range of numbers. | codefeedback |
Write a Python code to print a Pascal's triangle with a specified number of rows, where each number in the triangle should be the sum of the two numbers directly above it. The code should also validate the input, ensuring that the number of rows is a positive integer and less than or equal to 10. Additionally, the code... | codefeedback |
Write a recursive function that takes in a string of up to 100 characters and converts it into UTF-8. The function should return the number of bytes required to encode the string.
The function should follow the UTF-8 encoding rules:
- For characters in the range U+0000 to U+007F, the character is encoded as a single ... | codefeedback |
Write a code in Python to toggle all characters in a string and count the number of times each character appears. The string is: "Hello World!"
Additional Reasoning Steps:
1. Create an empty dictionary to store the count of each character.
2. Iterate through each character in the given string.
3. Toggle the character ... | codefeedback |
Perform some data analysis and find the average and median of the given data.
[12, 15, 6, 8, 10, 20, 5, 9, 13, 18, 22]
Please provide the solution in Python. | codefeedback |
Generate a code in Python to generate a list containing multiplication table up to a given number N. The code should be able to handle large values of N efficiently. Additionally, the code should only use basic arithmetic operations and not rely on any built-in functions or libraries. | codefeedback |
Please convert a doubly linked list to an array in JavaScript using an iterative approach, without using any built-in JavaScript functions or libraries.
You are given a `LinkedList` class and a `Node` class. The `LinkedList` class has two properties: `head` and `tail`, which represent the first and last nodes of the l... | codefeedback |
Generate a Python function to generate the Fibonacci sequence given a number n. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones. For example, the Fibonacci sequence for n = 5 would be [0, 1, 1, 2, 3].
Write a function called "fibonacci_sequence" that takes in a p... | codefeedback |
Write a function in Java that returns a random element from an array. However, the random element should not be equal to any of the previously returned elements.
int[] A = {3, 5, 7, 9, 12};
**Constraints:**
- The length of the array A is between 1 and 1000.
- The values in the array A are between -1000 and 1000.
- T... | codefeedback |
Write a SQL statement that returns the average age of people in the table, but excludes any individuals who are under the age of 18. Additionally, include a column in the result that shows the total count of people in each age group (age 18-30, age 31-40, age 41-50, etc.). | codefeedback |
Create a SQL query that returns the average number of orders per month for customers in California, where the orders should only include those that were placed in the last 6 months. Additionally, exclude any customers who have placed less than 5 orders in the last 6 months. | codefeedback |
Create an SQL query to find all customers from California who made more than 5 orders, whose total order amount exceeds $1000, and who have not made any returns within the past 6 months. | codefeedback |
Handle the given input, sort the users by age in ascending order, and output a CSV string with the format "user_id, name, age". The CSV string should only include users who are at least 18 years old and have an even age. Additionally, the output should be limited to a maximum of 100 users. | codefeedback |
Organize the given code snippet into an array data structure, but ensure that all strings starting with a vowel are placed at the beginning of the array, followed by the remaining strings. In addition, you need to remove any duplicate strings from the final array.
Example input: ["1", "Hello", "there", "10", "45", "Ap... | codefeedback |
Write an SQL query that returns the average value of all orders sent by customers who were born in the month of May and have made at least 5 orders, grouped by the year they were born.
Note: Assume that the table schema includes the columns 'customer_id', 'order_id', 'order_value', and 'birth_date'. | codefeedback |
Develop a Java function that takes a string and searches for the occurrence of a given character. However, you are not allowed to use any built-in functions or libraries for string manipulation or searching. Additionally, you should implement the search algorithm in a more efficient way, aiming for a time complexity of... | codefeedback |
Develop a Python code that takes a string as input, removes any punctuation marks and numbers from the string, converts it to all uppercase, and then converts all the vowels to their respective ASCII values. The code should also count the number of consonants in the resulting string and print the frequency of each cons... | codefeedback |
Write a MySQL query to get the sum of all values for a certain field in a particular table, but only for students whose age is greater than 18. Additionally, exclude any students whose name starts with the letter "A". | codefeedback |
Describe the feature of "promise" in JavaScript and implement a function that demonstrates the chaining of multiple promises. The function should accept an array of URLs and make HTTP requests to each URL sequentially using promises. The function should resolve with an array of the responses received from each request ... | codefeedback |
Write a regex expression to find all the words in a given sentence that contain exactly 4 characters and start with a vowel, but do not end with a vowel.
sentence = "This is a test sentence to find all 4 letter words starting with a vowel, excluding words that end with a vowel." | codefeedback |
Write a SQL query to select all entries in a given table with a value larger than 100 and the entries must be sorted in descending order of the values. Additionally, the query should only return the first 10 entries that satisfy the condition. | codefeedback |
Modify the code to only print the numbers that are divisible by both x and y. If no numbers meet this condition, print a message stating that there are no numbers divisible by both x and y. | codefeedback |
Write a function to calculate the parity of a given binary number using only bitwise operations. The function should take in a positive integer and return 1 if the number of set bits in the binary representation is odd, and 0 if it is even. The function should handle numbers up to 10^9. You are not allowed to use any o... | codefeedback |
Please write a Python program that sends an HTTP GET request to a given URL and parses the response to extract specific data.
Use the requests library to make the HTTP GET request and handle any exceptions that may occur.
Write a function called "get_specific_data" that takes in the URL as a parameter and returns a l... | codefeedback |
Write a SQL query to find all the entries in a given table that contain a specific "value" in the given column, where the value is case-insensitive. The query should also sort the results in descending order based on another column, and if there are multiple entries with the same value in the sorting column, sort them ... | codefeedback |
Change the following piece of Java code to make sure that the parameter passed is a valid date in the format "dd/mm/yyyy" and that it falls within a specified range of dates from January 1st, 1900 to December 31st, 2100. Additionally, implement the following additional requirements:
1. The method should throw a custom... | codefeedback |
Extend the given code to create a while loop that prints numbers from 1 to 11, but with the following additional requirements:
1. The loop should only iterate while the variable "i" is less than or equal to 11.
2. Inside the loop, the value of "i" should be incremented by 2 instead of 1.
3. Print the value of "i" only ... | codefeedback |
Parse the JSON data stored in a variable 'data' and print out the value of the key 'name'. Additionally, check if the key 'age' exists in the JSON data and print out its value if it does. If the key does not exist, print out a message stating that the key is not found.
Provide a piece of erroneous code that attempts t... | codefeedback |
Classify the given data according to their type, ensuring that the program can handle multiple inputs and store the results in a data structure. The program should also provide a user-friendly interface for inputting the data and displaying the classified results.
Erroneous code reference:
Implement a function that ta... | codefeedback |
Create a Python class object to store data about a professional basketball player, including their full name, team, position, height, weight, and career statistics (such as points per game, rebounds per game, and assists per game). Implement methods to update the player's statistics, calculate their player efficiency r... | codefeedback |
Create a class in Java that represents books in a library. Each book should have a title, author, genre, publication year, and availability status. The availability status should be represented by a boolean value indicating whether the book is currently available for borrowing. Additionally, the class should include me... | codefeedback |
Write a code to delete a 'customer' table from a MySQL database, but also ensure that all data contained in the table is backed up before deletion. Additionally, implement a transaction to rollback the deletion if any errors occur during the backup process. | codefeedback |
Write a SQL query to find all employees who have a performance rating of "excellent" in the past year, have received at least one promotion in the last 2 years, and have a salary increase of at least 10% compared to their initial salary when they joined the company. Additionally, only include employees who have a job t... | codefeedback |
Write a HTML and CSS code that creates a 4x4 grid. Each grid cell should have a different background color. The grid should have a border and each cell should have a unique ID. Additionally, the background color of each cell should change randomly every time the page is refreshed. | codefeedback |
Generate a unique seven-digit number that satisfies the following constraints: the first digit must be odd, the second digit must be a prime number, the third digit must be a multiple of 3, the fourth digit must be greater than 5, the fifth digit must be a perfect square, the sixth digit must be a single-digit prime nu... | codefeedback |
Describe the purpose of machine learning and provide an example of an algorithm commonly used in machine learning. Explain the working principles and steps involved in the algorithm, and discuss its strengths and limitations. Additionally, discuss how hyperparameter tuning can affect the performance of the algorithm an... | codefeedback |
Write a function that calculates the result when a power of 10 is raised to the power of n, where n is a positive integer less than or equal to 100. The function should not use any mathematical operations or built-in functions for exponentiation. Your solution should have a time complexity of O(n) and a space complexit... | codefeedback |
Create a Java program to count the occurrences of each unique lowercase letter in a given string, while ignoring any whitespace characters and punctuation marks.
String = "GPT models are a type of machine learning algorithms" | codefeedback |
Write a JavaScript function to find the number of matching items in two arrays. The function should also account for duplicate items in the arrays.
arr1 = [1, 2, 3, 4, 4]
arr2 = [3, 4, 5, 6, 6, 6]
Example:
findMatchingItems(arr1, arr2) should return 2, since 3 and 4 are the only matching items in the arrays.
Note:
-... | codefeedback |
Create a React component that updates itself with the current time every millisecond. Additionally, implement a button that, when clicked, stops the time update. Once stopped, the component should display a countdown from 1000 to 1, updating every millisecond. After reaching 1, the component should display a message sa... | codefeedback |
Write a PHP script to print the current week number, the day of the week, and the month for each day in the current week. Additionally, the script should only print the weekdays (Monday to Friday) and exclude weekends. | codefeedback |
Create a word frequency dictionary for the following sentence, taking into consideration that the words are case-insensitive and that punctuation marks should be excluded from the word count. Additionally, exclude any common stop words (e.g. "the", "is", "and") from the word count. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.