instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Perform a linear search in a list named 'mylist' and return the index of the last occurrence of a target value. The list can contain duplicate elements and can have a maximum length of 10^6. The target value can be of any data type. If the target value is not found in the list, return -1. | codefeedback |
Write a Python program to print out the list of prime numbers from 0 to the given limit, where each number is divisible by both 2 and 3. Additionally, the program should only use a single loop and should not make use of the modulo operator. limit = 10000 | codefeedback |
Increase the difficulty:
Use the Gaussian algorithm to learn the optimal parameters of a multiple linear regression model with multiple features.
Training dataset: {(x1,y1), (x2,y2), (x3,y3), ..., (xn,yn)}
However, this time, the training dataset is much larger and contains n data points. Each data point is represe... | codefeedback |
Create a dictionary from two lists with the same length, where the keys in the dictionary are obtained by converting the elements of mylist1 to uppercase and adding a suffix of "KEY". The values in the dictionary are obtained by converting the elements of mylist2 to integers and adding 10 to each value. Both mylist1 an... | codefeedback |
Sort a list of strings by their length in descending order without using the built-in sort method. The final list should contain only strings with lengths greater than 3.
mylist = ['this', 'is', 'a', 'long', 'list', 'of', 'strings'] | codefeedback |
Find the frequency of each letter in the given phrase "May the force be with you!" and return the letter(s) with the highest frequency. In case of a tie, return all the letters with the highest frequency. | codefeedback |
Create a method to checkout the content of a dictionary, ensuring that the keys are sorted in ascending order, the values are in all uppercase letters, with a maximum length of 50 characters, and each key-value pair is separated by a comma. The dictionary should also not contain any duplicate keys, and the method shoul... | codefeedback |
Calculate the sum of all the even numbers in a list named 'mylist'. The list may contain duplicate elements. The sum should only include numbers that are divisible by 3. You are not allowed to use any built-in functions for finding the sum. The list may have a maximum length of 100 elements. Additionally, the algorithm... | codefeedback |
Group a list of dictionaries by a shared key, while also sorting the groups in descending order based on another key. The groups should be sorted based on the sum of the values of the shared key. If two groups have the same sum, then sort them based on the minimum value of the other key. Implement the solution with a t... | codefeedback |
You need to read a list of strings, split each string into 2 substrings based on a specific character, and output the 2 substrings as a tuple. If the specific character is not found in a string, output "None" for that string.
Example:
Input: ['international', 'imagination', 'skyscraper']
Character: 'n'
Output: [('inte... | codefeedback |
Create a function to find if a given input is a prime number or not. Additionally, the function should return the smallest prime factor of the input if it is not a prime number. The function should be able to handle inputs up to 10^9 and provide the result within 2 seconds. | codefeedback |
Create a method to print all the prime numbers up to n, but the method should be written using a recursive approach instead of an iterative approach. Additionally, the method should exclude all prime numbers that are palindromic, i.e., their digits are the same when read forwards and backwards. | codefeedback |
Create a program to find the sum of all the prime numbers from 1 to n, where n is a positive integer provided by the user. The program should also display the number of prime numbers encountered during the process.
Reference erroneous code:
```python
def is_prime(num):
if num <= 1:
return False
for i ... | codefeedback |
Create a method to reverse a doubly linked list with the following constraints:
- Do not use any additional data structures or arrays.
- Do not use recursion.
- The method should have a time complexity of O(n), where n is the length of the linked list.
- The method should also handle a circular doubly linked list, wher... | codefeedback |
Create a Swift function to find the sum of elements in an array of integers, but with the following additional conditions:
1. The function should not use any built-in Swift functions that directly calculate the sum of an array or use loops.
2. The function should return 0 if the array is empty.
3. The function should ... | codefeedback |
Print out the content of a two-dimensional array in a clockwise spiral order, considering that the array can contain negative integers and decimal numbers. Additionally, you should handle arrays with uneven lengths and empty arrays, ensuring that the program does not crash or produce unexpected results. The array can h... | codefeedback |
Write a SQL query to find the most expensive item in the table, where the price is calculated based on multiple factors such as quantity, discount, tax, and the customer's loyalty level. The loyalty level is determined by the number of previous purchases made by the customer and can range from 1 to 5, with 5 being the ... | codefeedback |
Write a JavaScript function to sort an array of integers in ascending order, without using any built-in sorting functions or methods. The function should also handle negative numbers, duplicates, and floating-point numbers in the array, and return the sorted array. Additionally, the function should be implemented using... | codefeedback |
Write an R script to find the correlation between two variables and plot a scatterplot of the data. Additionally, handle missing values in the dataset by imputing the mean value of the variable. The script should also calculate and display the p-value of the correlation coefficient. | codefeedback |
Construct a SQL query to get the CustomerIDs, the number of orders made by each customer, and the average order amount for each customer from the Orders table. Only include customers whose total amount spent across all orders is greater than 500. | codefeedback |
To what type of data can the following MySQL query return if there is a third table involved?
SELECT *
FROM table1 t1
INNER JOIN table2 t2
ON t1.id = t2.id
INNER JOIN table3 t3
ON t2.id = t3.id
WHERE t1.name = 'John' AND t3.salary > 5000
#Erroneous Code#
To what type of data can the following MySQL query return if the... | codefeedback |
Write a function in Python that takes a list of numbers and returns the greatest difference between any two numbers in the list. However, you are not allowed to use any built-in functions such as max() or min().
Additionally, you are not allowed to use any looping constructs such as for or while loops. You must solve ... | codefeedback |
Write a C# program to create the list of prime numbers in a given range. However, you are not allowed to use any built-in functions or libraries for prime number generation. You must come up with your own algorithm to determine if a number is prime or not. Additionally, you should optimize your algorithm to have a time... | codefeedback |
Build a deep learning model in Python to predict the stock price of a given company, using only the company's historical financial data and market indicators. However, the model should also take into consideration the sentiment analysis of news articles related to the company, as well as any significant events or annou... | codefeedback |
Write a function that takes a string as input and reverses each word in the string while keeping the order of the words intact. Additionally, the function should ignore any punctuation marks and special characters in the string.
For example, if the input string is "Hello, World!", the output should be "olleH, dlroW!". | codefeedback |
Write a Java program to find the sum of elements in an n x n matrix, where n is a positive integer. The matrix is represented as a two-dimensional array of integers. The program should take input from the user for the size of the matrix and then prompt the user to enter the elements of the matrix.
The program should t... | codefeedback |
Write a query to display the average age of the students who have a grade higher than 80 and have scored above the average grade for their respective subjects, sorted in descending order of their age. Additionally, calculate the median age of these students.
Table Name: Students
Columns:
- student_id (integer)
- name... | codefeedback |
Write a query to retrieve all the customer names from an orders table where the customer is from a specific country and the order was placed within a certain time frame. Additionally, sort the results in descending order based on the total amount spent by each customer in their orders.
Table Name: Orders
Additional Co... | codefeedback |
Write code to retrieve data from a given MySQL table and filter the results based on multiple conditions. The conditions should be to retrieve books that have been published within the last 6 months, have an average rating above 4, and belong to a specific genre. The table name is "Books".
In addition, handle any pote... | codefeedback |
Generate a set of five English words starting with the letter "P" and ending with the letter "e", with a maximum length of 7 characters. Additionally, the second letter of each word must be a vowel and the third letter must be a consonant. | codefeedback |
Given two strings, determine if they are equal or not. However, the comparison should be case-sensitive, whitespace should also be considered, and punctuation marks should be ignored. Additionally, you are not allowed to use any built-in string comparison functions or methods. | codefeedback |
Explain the concept of a callback function in JavaScript and provide an example of its usage in a practical scenario. Additionally, discuss the benefits of using callback functions and compare them to other methods of handling asynchronous operations in JavaScript. Provide an example of how callback functions can be us... | codefeedback |
Create a Python function which takes an array and returns true if the array contains all unique values. The function should have a time complexity of O(n), where n is the length of the array, and should not use any additional data structures.
In addition, the function should handle arrays containing duplicate values b... | codefeedback |
Write a JavaScript program to replace all the vowels in a given string with '*' while preserving the case of the vowels. The program should also count the number of replaced vowels and return it as the second element of the resulting array.
Additionally, modify the program to also replace the consonants in the string ... | codefeedback |
Implement a binary search on the given array, but instead of searching for a specific value, search for the index of the smallest element in the array that is greater than or equal to a given target value. Return -1 if there is no such element.
Array = [1, 4, 5, 6, 7, 9]
Target value = 3
#Difficulty increased explanat... | codefeedback |
Create a doubly Linked List in C++ that supports the following operations: insertion at the front in constant time O(1), insertion at the end in constant time O(1), deletion of a specific node in linear time O(n), and reverse the order of the list in linear time O(n).
Additionally, the implementation should use a doub... | codefeedback |
Increase the difficulty of the given programming test question by adding complexity to the visualization task.
Visualize the following on a line chart:
Data points = [12, 13, 19, 20, 25, 28, 30, 29, 24, 22, 20, 18, 15, 14, 13, 12]
Reference erroneous code:
int dataPoints = [12, 13, 19, 20, 25]; // Missing semicolon a... | codefeedback |
Implement a stack data structure in Java with the following additional requirements:
1. The stack should have a maximum capacity of 1000 elements. If an attempt is made to push an element onto a full stack, it should throw a StackOverflowException.
2. The stack should support an additional operation called "getMinimum... | codefeedback |
Create a function that takes a string and returns a new string with each vowel capitalized and each consonant converted to its corresponding Morse code. The function should ignore any special characters or numbers in the string. The returned string should only contain alphabetic characters. The function should have a t... | codefeedback |
Write a code to estimate the value of pi (to 12 decimal places) using the Monte Carlo method.
In the Monte Carlo method, you generate a large number of random points within a square with side length 2. Then, you check how many of these points fall within a circle with radius 1 (inscribed within the square). The ratio ... | codefeedback |
Change the following code so that it prints only the prime numbers in reverse order from the given list, while also optimizing the time complexity of the solution.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for x in reversed(arr):
is_prime = True
if x < 2:
is_prime = False
elif x == 2:
is_prime... | codefeedback |
Implement a modified version of the insertion sort algorithm that sorts an array of integers in descending order. The array should be sorted using the modified algorithm.
Input:
[3, 4, 8, 1, 5, 7, 2, 9]
Output:
[9, 8, 7, 5, 4, 3, 2, 1]
Explanation:
In this modified version of the insertion sort algorithm, we start w... | codefeedback |
Write a function called `calculate_sum` that takes in a list of numbers as input and returns the sum of all the numbers in the list.
The function should meet the following requirements and constraints:
1. The function should handle both positive and negative integers, as well as floating-point numbers.
2. The functio... | codefeedback |
Suggest a Python code to parse a large XML document (containing millions of nodes) and efficiently extract specific data elements based on user input. Additionally, handle any potential errors or exceptions that may occur during the parsing process without compromising the performance. | codefeedback |
In Python, write code to identify whether a given string contains only numeric values, but the numeric values must be in scientific notation with an exponent. Additionally, the code should also check if the exponent is a prime number. | codefeedback |
Implement a heap sort algorithm in Java without using any additional data structures or libraries. The algorithm should only use a fixed-size array to perform the sorting. Additionally, the array size should be limited to 100 elements and the implementation should be able to handle duplicate elements in the array effic... | codefeedback |
Create a generic array using Java and sort it using the bubble sort algorithm. Additionally, add a condition to the sorting algorithm that allows for sorting the array in descending order instead of ascending order. The array should contain objects of a custom class that implements a specific interface and overrides a ... | codefeedback |
Describe how to use the following code to sort an array in ascending order. Additionally, the array should not contain any duplicate elements and the sorting algorithm should be optimized to have a time complexity of O(n log n) and a space complexity of O(1).
You are not allowed to use any built-in sorting functions ... | codefeedback |
Describe how to use the following code to generate a random password with the following requirements:
1. The password must be a string of length n.
2. The password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
3. The password must not contain any whitespace cha... | codefeedback |
Write SQL code to find the names of students who are enrolled in all three classes, have a minimum of 90% attendance in each class, and have an average grade of at least 80 in all three classes.
Table name: students
Columns: student_id, name, class1, class2, class3, attendance1, attendance2, attendance3, grade1, grade2... | codefeedback |
Generate a Frequency Table for the following sequence of characters using Python. The input sequence can contain any printable ASCII characters and can have a length of up to 10^6 characters. The frequency table should be implemented using a dictionary data structure. The time complexity of your solution should be O(n)... | codefeedback |
Sort the given words in lexicographical order. Additionally, the output should not contain any repeated words. The words should be case-insensitive. You are not allowed to use any built-in sorting functions or libraries.
Provide an optimized solution that has a time complexity of O(nlogn) and a space complexity of O(... | codefeedback |
Write a script in JavaScript to parse an XML document and extract specific data elements based on a set of complex conditions. The script should also handle any errors that may occur during the parsing process and provide appropriate error messages. | codefeedback |
Describe how to use the following code to calculate the sum of all elements in an array in Java, without using the "+" operator, and without using any loops or recursion.
public static int calcSum(int[] arr) {
int sum = 0;
for (var i = 0; i < arr.length; i++) {
sum = add(sum, arr[i]);
}
return ... | codefeedback |
Convert this number from decimal to binary using bitwise operations only. However, you are not allowed to use the bitwise shift operators (<< and >>) or the bitwise not operator (~).
#Given Test with Erroneous Code#
Convert this number from decimal to binary using bitwise operations only.
Erroneous Code:
int number =... | codefeedback |
Write a JavaScript function that takes in a string and returns the string with each word reversed. The function should also remove any duplicate words from the string and return the result in reverse alphabetical order. | codefeedback |
Write a SQL query to find the highest salary of a female employee who has been working at the company for at least 5 years and is not in a managerial position in the salary table. Additionally, the query should exclude employees who have received any performance warnings in the past year. | codefeedback |
Write an R function to calculate the mean of a numerical vector, without using any built-in functions or loops. However, you are allowed to use only a single recursive function to accomplish this task. | codefeedback |
What is the purpose of the "break" keyword in the C programming language and how does it differ from the "continue" keyword? Explain with an example where both keywords are used within a loop to manipulate an array. Additionally, analyze the time and space complexity of the algorithm. | codefeedback |
Write a recursive function in Java to print all the prime numbers in a given list in reverse order.
int[] list = {21, 34, 54, 77, 92}; | codefeedback |
Create a Java program that reads two positive prime numbers from the user and prints the sum of their prime factors. The program should also validate that the input numbers are prime numbers and should terminate if the input numbers are not prime. | codefeedback |
Write a function in Python that takes in two strings and concatenates them together with a space in between. The function should also reverse the order of the characters in the concatenated string. Additionally, the function should remove any duplicate characters from the concatenated string. | codefeedback |
Create a Python program that extracts all unique words from a given sentence and counts the frequency of each word. The program should handle sentences with punctuation marks and words in different cases (uppercase and lowercase). Additionally, exclude common stop words such as "the", "and", "a", etc. from the final li... | codefeedback |
Write a C++ program to find all pairs of prime numbers whose sum is equal to a given number, using a multi-threaded approach where each thread checks a range of numbers for primality. The program should take an input from the user for the target sum. The program should print all the pairs of prime numbers that satisfy ... | codefeedback |
Create a bash script that prints out "Hello World" ten times, but each time it should be printed in a different color. Additionally, make sure that the script terminates if any of the color codes provided are invalid. | codefeedback |
Write a CSS style to add a yellow background to the body of a webpage only when the viewport width is greater than 600 pixels, the user has scrolled down more than 50% of the page, and the user's device is a mobile device with a touch screen. | codefeedback |
Create a Python program to generate the Fibonacci series up to a given number n, but with the following additional requirements:
1. Use recursion to calculate each Fibonacci number.
2. Implement memoization to optimize the recursive calculation.
3. Use generators to yield each Fibonacci number one at a time, rather tha... | codefeedback |
Write a function that takes a string and returns a dictionary counting each unique character in the string. The function should only count alphabetical characters and ignore any non-alphabetical characters. The returned dictionary should be sorted in descending order based on the count of each character. The function s... | codefeedback |
Read the input text and reverse it character by character, taking into account only alphanumeric characters and ignoring any punctuation or special characters. Additionally, ensure that the reversed text maintains the same capitalization as the original text. This is a sample text. | codefeedback |
Please write a function in Java to sort a given array of strings into ascending order using a merge sort algorithm. The function should have the following signature:
void mergeSort(String[] array, int low, int high)
The function should sort the elements in the array from index low to index high (inclusive) using the m... | codefeedback |
Concatenate the two strings below, with a space inserted between them. Ensure that the resulting string does not contain any duplicate characters. Additionally, the resulting string should be sorted in descending order.
A = "Hello"
B = "World!" | codefeedback |
Create a responsive HTML page that displays the words "Hello, World!" in different colors and fonts. The page should also include a button that, when clicked, changes the background color of the page randomly. Additionally, the text "Hello, World!" should be animated to fade in and out continuously. The font size of th... | codefeedback |
Print the following 2D matrix in row-major order. You are not allowed to use any nested loops or recursion. Additionally, the solution must be implemented in constant space complexity and have a time complexity of O(n), where n is the total number of elements in the matrix. | codefeedback |
Suggest a sorting algorithm to sort the following array in descending order. The algorithm should have a time complexity of O(nlogn) and must be implemented using recursion. Additionally, the sorted array should be stored in a new array and the original array should remain unchanged. The algorithm should also be space ... | codefeedback |
Given a string in snake_case, convert it to camelCase. In camelCase, the first letter of each word (except the first word) is capitalized and all the words are concatenated together without any spaces.
Example:
Input: this_string_should_be_converted_to_camelCase
Output: thisStringShouldBeConvertedToCamelCase
Addition... | codefeedback |
Modify the following Java program to find the area of a trapezoid with user input for the lengths of the parallel sides and the height.
Requirements:
- The program should prompt the user to enter the lengths of the parallel sides and the height of the trapezoid.
- The program should validate that the user input is a p... | codefeedback |
Generate a 3x3 matrix of random real numbers in the range of -10.0 to 10.0. Sort the matrix in ascending order, ensuring that the sum of each row is greater than 5. Calculate the sum of the numbers in the first row. Finally, print the sorted matrix and the sum of the first row. | codefeedback |
Calculate the harmonic mean from a given list of positive integers greater than zero, where the length of the list is at least 5 and at most 10. The list may contain duplicates and the integers can be in any order.
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5] | codefeedback |
Create a JavaScript function that takes in two parameters: a start date in the format "yyyy-mm-dd hh:mm:ss" and an end date in the same format. The function should return the number of minutes that have passed between the two dates, rounded to the nearest whole number. The start date should always be earlier than the e... | codefeedback |
In C++, search a given string for a given sub-string and return the starting index of each occurrence. However, the implementation must be case-sensitive and the search should only consider exact matches (no partial matches or overlapping matches). | codefeedback |
Write a bash script to list the content of the current directory. The script should only display files with a .txt extension and sort them in descending order based on the file size. The output should include the file name, size, last modified date, and the number of lines in each file.
In addition, the script should ... | codefeedback |
Create a JavaScript object to represent a person's name, age, and address, with the following additional constraints:
1. The name must be a string of alphabetic characters and cannot exceed 50 characters in length.
2. The age must be a positive integer between 1 and 100.
3. The address must be a string of alphanumeric... | codefeedback |
Create a Python function that takes in a string as input and returns a dictionary where the keys are the unique characters in the string and the values are lists containing the indices of each occurrence of the character in the string. The function should ignore any characters that are not letters. Additionally, the fu... | codefeedback |
Generate a 10-element tuple of random prime numbers between 500 and 1000 using Python. | codefeedback |
Implement a function to calculate the result of raising 2 to the power of n, where n is an integer between 1 and 10^9. The function should have a time complexity of O(log n). | codefeedback |
Write a Python function to count the letters in a given sentence, excluding any numbers, special characters, and punctuation marks, and return a dictionary of letter counts. The function should be case-insensitive and should not count spaces. The sentence will not exceed 1000 characters. Additionally, the function shou... | codefeedback |
Write a query in SQL to list the employee information from the given Employee table in descending order of their salaries, but exclude any employees whose salary is below a certain threshold set by the user. Additionally, the query should calculate and display the average salary for each department and include only the... | codefeedback |
Generate an array of prime numbers up to and including the number N, where N is a positive integer less than or equal to 100. The solution should be optimized to have a time complexity of O(N log log N). | codefeedback |
Create a Python program to generate a random string of 10 characters. The program should ensure that the string contains at least two uppercase letters, two lowercase letters, two digits, and two special characters. The generated string should also not contain any repeated characters. | codefeedback |
Write a SQL query to select the row with the customer id "CID001" from the customers table, but exclude any rows where the customer's status is "Inactive". Additionally, sort the result by the customer's last name in descending order. | codefeedback |
Write a function in Python to check if two strings are an anagram or not, but without using any built-in string manipulation methods or libraries. Additionally, the function should handle cases where the input strings contain special characters and whitespace. | codefeedback |
Create a CSS rule to make all h1 elements red in color. Additionally, add a hover effect that changes the color to blue. Ensure that the hover effect only applies to h1 elements that are inside a div with a class of "container". | codefeedback |
Create a PHP class for a user that includes the following functionality:
1. Implement a constructor that takes in parameters for the user's name, email, and password.
- Validate that the name, email, and password are not empty.
- Check that the email is in a valid format.
2. Add a method to validate the email f... | codefeedback |
Write a Python code to print the phrase "Hello World!" on the console 10 times, but each time the phrase should be printed in a different color. | codefeedback |
Write a JavaScript function that takes in a string and returns a new string where every word is capitalized and the words are separated by a hyphen. Use only pure JavaScript (no built-in methods such as .toUpperCase() or .split() allowed). | codefeedback |
Edit the provided CSS rule to make all elements with the class "myClass" have a bold font-weight and a background color of #F0F0F0. Additionally, the font-size should be set to 18px and the text color should be #333333. However, make sure that the CSS rule only targets the direct children of elements with the class "my... | codefeedback |
Identify the most efficient data structure to store a list of strings, while minimizing the time complexity for searching for a specific string within the list. Additionally, propose an algorithm to sort the list of strings in descending order of their lengths, while minimizing the space complexity. Ensure that the sor... | codefeedback |
Using the provided HTML, add a class attribute to all h1 tags within a specific section of the page, so that their styles can be updated. The section is identified by a unique id attribute. Additionally, write a JavaScript function that dynamically creates a new section with an h2 tag inside it, and add a class attribu... | codefeedback |
Write a JavaScript code to add two numbers using a prompt, but instead of adding two numbers directly, create a recursive function that takes in two numbers as parameters and returns their sum. Additionally, the function should check if either of the input numbers is negative, and if so, convert it to its absolute valu... | codefeedback |
Write an SQL query to select the names, ages, and departments of all employees from the table 'employees' who are currently employed, have an age greater than 25, and belong to departments with more than 10 employees. Additionally, order the results in descending order based on their ages, and if there are employees wi... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.