instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Make a code to determine whether a given number is prime or not. Additionally, optimize the code to reduce the time complexity to O(sqrt(n)). | codefeedback |
Create a function to calculate the sum of all cubes from 1 to n, where n is a positive integer. | codefeedback |
Create a program to count the total characters in a string, but with the following additional requirements:
1. The program should ignore whitespace characters and only count alphabetic characters.
2. The program should also count the number of words in the string.
3. The program should display the frequency of each ch... | codefeedback |
Convert the given string to uppercase and reverse the order of the characters.
Input: Hello World
Output: DLROW OLLEH | codefeedback |
Concisely describe how a Doubly Linked List works and provide the implementation for a method that reverses the order of the elements in the list. | codefeedback |
Create a function to check whether a number entered is a strong prime number or not.
A strong prime number is a prime number that satisfies the following conditions:
1. It is greater than 1.
2. It is not a perfect square.
3. It is not a multiple of the first three prime numbers (2, 3, and 5). | codefeedback |
Develop a function that swaps the positions of two elements in an array, while maintaining the relative order of the other elements.
#Additional Instructions#
1. The function should take in the array and the indices of the two elements to be swapped as input parameters.
2. The function should validate the input para... | codefeedback |
Write a C++ program that prints out all the prime numbers up to 1,000,000. | codefeedback |
Create a program in Python that calculates the average of numbers in a list, but with the following additional requirements:
1. The program should handle an empty list and return an appropriate error message.
2. The program should handle a list that contains non-numeric elements and skip them while calculating the ave... | codefeedback |
Create a Python function that takes in a string and returns a new string with all special characters removed. Special characters include any non-alphanumeric characters. The function should have a time complexity of O(n) and should not use any built-in string manipulation functions such as replace() or translate(). | codefeedback |
Create an HTML form with two input boxes and a submit button. Upon submission, validate the input values using JavaScript to ensure that:
- The first input box should only accept numeric values greater than or equal to 100.
- The second input box should only accept alphabetic characters (both uppercase and lowercase) a... | codefeedback |
Edit the above PHP function so that it also checks if a given number is prime. Additionally, you should implement a caching mechanism to store previously calculated prime numbers and use this cache to optimize the prime number checking process. | codefeedback |
Modify the function to also remove all whitespace and punctuation from the string, and convert all characters to lowercase. | codefeedback |
Suppose there is an array of numbers. Write a Java program to sort the array in ascending order using a divide and conquer algorithm such as merge sort or quicksort. The program should have a time complexity of O(n log n) and should be implemented without using any built-in sorting functions or libraries. Additionally,... | codefeedback |
What would be the resulting string after executing this code?
a = "Hello"
b = "World"
c = ""
for i in range(len(a)):
c += a[i]
for j in range(len(b)):
c += b[j]
c = c + "!"
Note: This rewritten test increases the difficulty by using nested loops to concatenate the strings instead of using the built-i... | codefeedback |
Create an object in JavaScript that performs a task given a condition, where the condition is that the object must be able to handle and process asynchronous tasks and callbacks. | codefeedback |
Write a code to find the square of the first n numbers, where n is a positive integer. The code should also calculate the sum of the squares and return both the sum and the list of squares. | codefeedback |
Given a two-dimensional array of integers, write a code to find the maximum sum of any subarray within each row, where a subarray is defined as a contiguous block of elements in the same row. The code should return the maximum sum for each row. Additionally, the code should check for and handle any negative values in t... | codefeedback |
Given a nested list, write code to convert the list into a nested dictionary.
list1 = [["John", {"Doe": 23}], ["Jane", {"Smith": 32}]]
# Note #
This rewritten test adds complexity by introducing a nested list and nested dictionaries, requiring more advanced manipulation of data structures. | codefeedback |
What will happen when the following code is executed?
a_list = [1, 2, 3, 4, 5]
for i in a_list:
a_list.insert(0, i + 6)
print(a_list) | codefeedback |
Create a balanced binary search tree in JavaScript. The tree should be self-balancing and maintain a height of O(log n) even after multiple insertions and deletions. | codefeedback |
Write a code to find the missing number in the given array, where the array is sorted in ascending order and contains distinct integers.
A = [1, 2, 3, 4, 6, 7, 8]
Additional instructions:
- Your code should have a time complexity of O(log n).
- You are not allowed to use any built-in functions or libraries to find the... | codefeedback |
Write a code to print out all the prime numbers between 2 and 10,000, satisfying the following conditions:
1. Implement the Sieve of Eratosthenes algorithm.
2. The code should use a multithreading approach to improve performance.
3. The code should be able to handle inputs up to 1 million in a reasonable amount of time... | codefeedback |
Given the following dictionary, change the value of the key "a" to "apples" only if the length of the current value is greater than 5 characters, otherwise change it to "grapes".
my_dict = {"a": "bananas", "b": "pears"} | codefeedback |
Generate a list of prime numbers from 1 to 1000. | codefeedback |
Write a Python function to check whether a string has all unique characters. The function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Write a Python program to find out the common items from two given arrays. However, the program should not use any built-in functions or libraries to find the common items. The program should only use basic programming constructs such as loops and conditionals. Additionally, the program should not modify the original a... | codefeedback |
Write a script to generate the Fibonacci sequence up to a certain number.
Number of elements to generate: A random prime number between 10 and 100. | codefeedback |
Write a script to delete an element from an array given its index. The index should be verified to be within the bounds of the array before performing the deletion. If the index is out of bounds, an appropriate error message should be displayed. The remaining elements in the array should be shifted to fill the empty sp... | codefeedback |
Design a program to flatten a given list of lists, where each inner list may contain any combination of integers, floats, strings, and dictionaries. The program should flatten the list by removing any nested lists and merging their elements into a single flat list. The final list should maintain the order of the origin... | codefeedback |
Create a loop to iterate over characters in a given string in reverse order.
Sample string s = "Hello World" | codefeedback |
Design a program to compare two sorted lists and returning list with the common elements. The program should also return the indices of the common elements in both lists. The lists can contain duplicates and the common elements should be counted multiple times based on their occurrences in both lists.
list_one=[5, 10,... | codefeedback |
Design a program to find the intersection of two given arrays. The intersection is defined as the common elements between the two arrays.
list_one=[5, 10, 15, 20, 25]
list_two=[15, 17, 20, 22, 25, 27]
You are not allowed to use any built-in intersection functions or sets.
Write a program that prints the intersection... | codefeedback |
Design a program to find the nth Fibonacci number that is also a prime number.
n: 10 | codefeedback |
Generate a function to multiply two integers using bitwise operations. The function should have a time complexity of O(log n), where n is the larger of the two input integers. | codefeedback |
Design a program to find the occurrence of a given character in a given string, but the program should ignore any occurrences of the character within a substring enclosed in double quotes. Given string: "Hello "World!" ooo" Character to find: o | codefeedback |
Given a binary tree, write a recursive function to find the sum of all the nodes in the tree. | codefeedback |
Create a function that takes in a list of integers and returns a new list containing only the prime numbers from the original list. The function should have a time complexity of O(n√m), where n is the length of the original list and m is the maximum value in the original list. | codefeedback |
Edit a python function to generate the fibonacci sequence up to the nth term, where n is a positive integer greater than 2. The function should also return the sum of all the even numbers in the fibonacci sequence. | codefeedback |
Use the back-propagation algorithm to learn the weights of a given neural network with multiple hidden layers and activation functions. Additionally, implement regularization techniques such as L1 or L2 regularization to prevent overfitting. | codefeedback |
Create a project in random forest to predict the target variable given a set of predictor variables.
predictor_vars = ["age", "occupation", "education_level"]
target_var = "income"
#Erroneous Code#
In the given code snippet, there is an error in the definition of the predictor_vars list. Instead of including only "age... | codefeedback |
Write an API to return the average transaction amount of a customer, where the transactions must be within the last 30 days and the customer must have made at least 10 transactions. | codefeedback |
Suggest a better algorithm to find the minimum element in a given array, but you are not allowed to use any looping constructs or recursion. | codefeedback |
Create an HTML table with 5 columns containing the given data, as well as additional data about each person.
Data:
Name | Age | Hobby | Occupation | Favorite Color
Alice | 20 | Reading | Teacher | Blue
Bob | 25 | Outdoor activities | Engineer | Green
In addition to displaying the original data, you will need to add tw... | codefeedback |
Explain the difference between an API and a web service and provide examples of each. | codefeedback |
Suggest an efficient data structure to store a list of words that can handle searching for words with a specific prefix and allow for efficient insertion and deletion operations. | codefeedback |
Write a Java program to find all pairs of integers in an array that sum up to a given target integer. The program should print the indices of these pairs.
The input consists of an array of integers and a target integer. The output should be a list of pairs, where each pair is represented by the indices of the two int... | codefeedback |
Increase the difficulty by adding a constraint to the problem.
Complete the following code to shuffle an array of elements without using the random.shuffle() function or any built-in shuffling function.
#Declaring an array
arr = [1, 2, 3, 4, 5]
# Your code
def shuffle(arr):
You need to implement the shuffle() funct... | codefeedback |
Use the Gaussian algorithm to learn the optimal parameters of a 2D linear regression model.
Training dataset: {(x1,y1), (x2,y2), (x3,y3)}
However, this time, the training dataset is much larger and contains n data points. Each data point is represented by a pair (xi, yi) where xi is a real number and yi is the corresp... | codefeedback |
Use the 'requests' library to retrieve the HTML content of a website.
url = "https://www.example.com"
Requirements:
1. Retrieve the HTML content of the website using the 'requests' library.
2. Implement error handling for any potential exceptions that may occur during the retrieval process.
3. Parse the HTML content t... | codefeedback |
Use the 'subprocess' library to execute a shell command and store its output. The command should be an interactive shell command that requires user input. | codefeedback |
Find the frequency of each letter in the given phrase "May the force be with you!" and return the letter with the highest frequency. | codefeedback |
Create a method to checkout the content of a dictionary, ensuring that the keys are sorted in ascending order and that the values are in all uppercase letters, with a maximum length of 50 characters. | 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.
Example:
mylist = [{'name': 'j... | codefeedback |
Print out the content of a two-dimensional array in a clockwise spiral order.
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] | 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. | 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. | codefeedback |
Create a method to reverse a 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. | codefeedback |
Create a JavaScript function that prints out the numbers from 1 to n, but only if the number is divisible by 3 or 5. | codefeedback |
Create a Swift function to find the sum of elements in an array of integers, but with the following 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 handle both... | codefeedback |
Write SQL code to find the product details of the item with ID 1234. Also, include the average rating of the product and the number of times it has been purchased. | 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, and tax. | 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 and duplicates in the array, and return the sorted array. | 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. | 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. | 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 |
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 | 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.
For example, if the input string is "Hello World!", the output should be "olleH dlroW!". | codefeedback |
Write code to retrieve data from a given MySQL table and filter the results based on a specific condition. The condition should be to retrieve books that have been published within the last 6 months. The table name is "Books". | codefeedback |
Calculate the factorial of a given number using recursion.
The number is 12 | codefeedback |
Implement a function that checks if a given binary tree is a binary search tree. | 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. | 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.
Table Name: Orders
Additional Constraints: Only retrieve customer names for orders placed between a start date and end date, and the customer must be ... | codefeedback |
Given two strings, determine if they are equal or not. However, the comparison should be case-sensitive and whitespace should also be considered. Additionally, you are not allowed to use any built-in string comparison functions or methods. | codefeedback |
Create a doubly Linked List in C++ that supports the following operations: insertion at the front, insertion at the end, deletion of a specific node, and reverse the order of the list. | codefeedback |
Filter the provided array by returning only even numbers and then sort the resulting array in ascending order.
numbers = [1, 6, 3, 8, 5, 2] | 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. | 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. | codefeedback |
Implement a stack data structure in Java with the following additional requirements:
1. The stack should have a maximum capacity of 100 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 |
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 a given target value. Return -1 if there is no such element.
Array = [1, 4, 5, 6, 7, 9]
Target value = 3 | codefeedback |
Reorganize the provided data into an HTML table and add the following functionality:
1. Sort the table alphabetically by the name of each student.
2. Add a column that displays the length of each student's name.
3. Add a column that calculates and displays the year each student was born in, assuming the current year i... | codefeedback |
Increase the difficulty of the given programming test question by adding additional requirements and constraints.
#Rewritten Test#
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 an... | codefeedback |
Create a function that takes a string and returns a new string with each character capitalized. The function should also ignore any special characters or numbers in the string. The returned string should only contain alphabetic characters. The function should have a time complexity of O(n), where n is the length of the... | codefeedback |
Add a requirement to convert all words in the array to uppercase before appending the string "Welcome to the party" at the end.
words = ["hello", "there"] | codefeedback |
Change the following code so that it prints only the prime numbers in reverse order from the given list.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for x in arr:
is_prime = True
if x < 2:
is_prime = False
for i in range(2, int(x ** 0.5) + 1):
if x % i == 0:
is_prime = False
... | 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). | codefeedback |
Write a JavaScript function that detects the browser language and displays a response message in that language. The function should also allow the user to specify a default language in case the browser language is not supported. Additionally, the function should handle cases where the browser language is a variant of a... | codefeedback |
Suggest a Python code to parse an XML document and extract specific data elements based on user input. Additionally, handle any potential errors or exceptions that may occur during the parsing process. | 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. | 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 |
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. | 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. | codefeedback |
Implement a bubble sort algorithm in a programming language of your choice to sort an array of integers in ascending order. The algorithm should have a time complexity of O(n^2) and should not use any built-in sorting functions or libraries. | codefeedback |
Write a script in JavaScript to parse an XML document and extract specific data elements based on a set of complex conditions. | codefeedback |
Write SQL code to find the names of students who are enrolled in all three classes and have a minimum of 90% attendance in each class.
Table name: students
Columns: student_id, name, class1, class2, class3, attendance1, attendance2, attendance3 | codefeedback |
Generate the Fibonacci sequence up to the 10th number, while ensuring that the runtime complexity of your solution is O(log n). | codefeedback |
Convert this number from decimal to binary using bitwise operations only.
128 | codefeedback |
Create a C++ program to calculate the sum of numbers in an array, but only include numbers that are divisible by both 2 and 3.
std::vector<int> numbers = {2, 4, 6, 9, 12, 15}; | codefeedback |
Write an R function to calculate the mean of a numerical vector, without using any built-in functions or loops. | 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. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.