instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a random number generator in Python that returns a random prime number in the range of 1-100. | codefeedback |
Create a program that assigns a unique ID to each element of an array. The ID should be a combination of a randomly generated alphanumeric string and a timestamp. The alphanumeric string should be at least 10 characters long and should contain a combination of uppercase letters, lowercase letters, and numbers. The time... | codefeedback |
Create a list in Python of elements 0-9 in ascending order, but each element should be repeated twice. | codefeedback |
Given an array of integers, write an algorithm to find the maximum difference between any two elements in the array. However, the algorithm should have a time complexity of O(n) and should use only a constant amount of extra space.
nums = [3, 2, 7, 1, 4] | codefeedback |
Design a data structure to store books that keeps track of page numbers and allows for efficient searching and retrieval of pages based on certain criteria, such as the page number falling within a specific range or the page containing a particular keyword. Additionally, the data structure should support efficient inse... | codefeedback |
Write a recursive algorithm to generate all possible combinations of balanced parentheses given a certain number of pairs. | codefeedback |
Find the sum of the sequence of numbers from 1 to 10, considering only the even numbers and excluding any numbers divisible by 3. | codefeedback |
Create a class in Python that represents a binary tree. The class should have the following functions:
1. `insert(value)` - This function should insert a new node with the given value into the binary tree.
2. `search(value)` - This function should return `True` if the given value is present in the binary tree, and `F... | codefeedback |
Create a C++ program that uses command line arguments to print out the argument passed in as a string. The program should also check if the argument is a valid string and display an error message if it is not. | codefeedback |
Given an array of size n and a target number, find the index of the first occurrence of the target number in Java. The array may contain duplicates.
Please solve the problem with a time complexity of O(log n) and without using any built-in search functions such as indexOf(). | codefeedback |
Given a JSON object that contains multiple nested levels, write a Python program to convert it into a Pandas dataframe. The nested levels can include lists, dictionaries, and multiple levels of nesting. The program should be able to handle complex JSON structures and convert them into a structured Pandas dataframe. | codefeedback |
Calculate the number of valid permutations of length n with respect to a given set of n distinct elements, where each element can only appear once in a permutation and there are certain constraints on the order of elements.
n=5
#Explanation#
In a valid permutation, each element from the given set of n distinct element... | codefeedback |
Create a SQL query to select the maximum salary for each department from the "Salary" table, while also excluding any departments where the maximum salary is below $100,000. | codefeedback |
Write code to sort a Python list of tuples based on their second element in the tuple. The second element in each tuple represents the number of occurrences of the first element in a separate list. The tuples should be sorted in ascending order based on the number of occurrences. If two tuples have the same number of o... | codefeedback |
What is "branching" in version control systems and how does it differ from "merging"? Provide an example scenario where branching and merging would be useful in a collaborative software development project. | codefeedback |
Implement a function in programming that demonstrates the concept of polymorphism. The function should take in two parameters: a list of shapes (each shape represented as a dictionary with attributes such as "type" and "area") and a string indicating the operation to be performed on the shapes (e.g., "calculate total a... | codefeedback |
Write a code snippet to add two numbers provided in two lists. The length of the lists will always be the same. list1 and list2 will contain integers in the range of 0 to 9. The result should be returned as a new list. The sum of the numbers in the lists can be larger than 9, so the code should handle carrying over the... | codefeedback |
Convert this MySQL query to MongoDB and return the result in descending order of customer's last name. Make sure the query runs efficiently for large datasets. | codefeedback |
You are given two strings, A and B. Write a function to delete the characters in A that also appear in B. Additionally, the function should also delete any characters in A that appear more than once consecutively.
A = 'abcbbdef'
B = 'abcdc'
After applying the function, A should be modified to 'ae'. | codefeedback |
Which language is used to develop applications for the Android platform? Provide an example of a common error that developers may encounter while using this language and explain how to fix it. | codefeedback |
Classify a given paragraph as having a positive or negative sentiment, considering the presence of sarcasm. The customer service was absolutely horrendous, and the wait felt like eternity. Additionally, the algorithm should also detect any contradictory statements within the paragraph. | codefeedback |
Write a node.js program to get the name of the day for a given date, considering leap years and accounting for different calendar systems. | codefeedback |
Write a dynamic programming algorithm to solve the following problem:
Given an array of positive integers, find the maximum sum of a subsequence with the constraint that no two numbers in the sequence are adjacent to each other. For example, for the input array [1, 2, 3, 4, 5], the maximum sum of a subsequence would b... | codefeedback |
Edit a JavaScript program to input a number and output its factorial using a recursive function. The program should also include error handling to check if the input is a positive integer and display an appropriate error message if not.
Sample Input:
let n = 5;
Sample Output:
The factorial of 5 is 1 | codefeedback |
Create a sorting algorithm in Python that will sort an array of numbers in ascending order.
The time complexity of the algorithm should be O(nlogn) or better. You are not allowed to use any built-in sorting functions or libraries.
The algorithm should be stable, meaning that the relative order of equal elements shoul... | codefeedback |
Create a bash script that sorts a list of numbers in ascending order. Additionally, implement a function to calculate the sum of the sorted numbers. The list of numbers is stored in a variable named "list". Use the provided erroneous code as a reference to increase misdirection:
list = [3,12,1,4,5]
# Erroneous code r... | codefeedback |
Create an XML document with five elements "Company", "Product", "Price", "Quantity", and "Total Price". The "Quantity" element should have a minimum value of 1 and a maximum value of 1000. The "Total Price" element should be the product of the "Price" and "Quantity" elements. | codefeedback |
Write a function in Java to find the sum of all the elements in a two-dimensional array. The array may contain positive and negative integers.
int arr[][]={{-5,10,3},{2,-7,4},{1,6,-2}};
Note: The array may have any number of rows and columns, and the elements can be of any value. | codefeedback |
Create an array of length n, containing all even numbers starting from 0, where each number is the sum of its previous two even numbers in the array. | codefeedback |
Write an SQL query to display the 10 most recently added products, but exclude any products that have been marked as discontinued. | codefeedback |
Classify the given sentence into either Affective or Predicate. You should also identify the tense of the sentence and extract the adjectives used. | codefeedback |
Create a C# class to serialize a JSON object, but only include properties that have a specific attribute applied to them. | codefeedback |
Create a Python class that processes a string of text and performs the following operations:
1. Reverses the order of characters in the string.
2. Counts the number of occurrences of each character in the string and returns a dictionary with character-frequency pairs.
3. Returns the longest continuous substring that co... | codefeedback |
Train a SVM model on the given input data to classify the output as either "yes" or "no". Each input data point should be represented as a tuple (x1, x2, y) where x1 and x2 are real numbers and y is either "yes" or "no". The SVM model should have a minimum accuracy of 90% on a separate validation dataset of at least 10... | codefeedback |
Write a code in Java for creating an instance of an interface that implements multiple interfaces, each with its own unique methods and functionality. | codefeedback |
Create a function in R that will return the maximum number in a given vector, but the vector can contain both numeric and character values. If the vector contains character values, the function should return the maximum number as if the character values were converted to their corresponding ASCII values. If the vector ... | codefeedback |
Create a PHP class that has two properties, an id and name. Implement a method called "getFullName" that returns the full name of the object. The full name should be a combination of the id and name, separated by a hyphen.
Additionally, create a static variable called "counter" that keeps track of the number of objec... | codefeedback |
Describe the working of a set in Python, including how to implement set operations such as union, intersection, and difference, and provide an example code that demonstrates the usage of sets in a real-life scenario. | codefeedback |
Create a SQL query to find the total payments made by each customer in the last 30 days, along with the total payments made by all customers in the last 30 days. | codefeedback |
Given a balanced binary search tree (BST), where each node contains a key and a value, provide an algorithm to delete a node with a specific key k from the BST. Additionally, ensure that the algorithm maintains the balance of the tree after deletion. | codefeedback |
Write a function in JavaScript which takes a situation as a parameter and returns the probability of success. The situation includes various factors such as economic indicators, historical data, news sentiment, and technical analysis. The function should analyze these factors and provide a more accurate and sophisticat... | codefeedback |
Create a HTML page with a form that takes user input and performs some action when the user clicks the submit button. However, the action should involve dynamically generating a graph based on the user input, using a specific JavaScript library such as D3.js or Chart.js. | codefeedback |
Create a query to find the total payments from one customer in the last 10 months, while also retrieving the details of each payment including the payment date, amount, and payment method. Additionally, the query should return the total number of payments made by the customer in the last 10 months. | codefeedback |
Implement an algorithm to find all the sets of three distinct numbers in an array which adds up to a given number. The array will contain positive integers only and can have duplicate values. The output should be in ascending order and should not contain any duplicate sets.
Array: [2, 5, 8, 2, 3, 5, 9], Number: 10 | codefeedback |
Create a function that takes two arguments, a string and a character, and replaces all occurrences of the character with the string in JavaScript. The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1). | codefeedback |
Write a SQL query to get the average of all the numbers from a single column in a table called "sales". The column name is "amount". | codefeedback |
Create an efficient algorithm to find the longest common substring from two given strings. The algorithm should have a time complexity of O(n^2), where n is the length of the longer string. The algorithm should also handle cases where the strings can contain special characters and are case-sensitive. Additionally, the ... | codefeedback |
Suggest a way to convert the following XML code into JSON in Python, while also validating the XML structure and handling any potential errors or inconsistencies in the data. | codefeedback |
Visit the official API documentation for a web service of your choice and create a Python code that makes a POST request with a JSON payload. The payload should contain at least three different data fields, with each field having specific requirements. Additionally, the code should handle any possible errors or excepti... | codefeedback |
Create a visualization to compare the customer preferences of two websites.
Website 1 has 4000 customers and their favourite products are video games and consoles. Each customer has also rated their satisfaction level with the website on a scale of 1 to 5.
Website 2 has 5000 customers and their favourite products are m... | codefeedback |
You need to generate a virtual object with React.js that can be dynamically updated based on user input and automatically refresh every 5 seconds. | codefeedback |
Develop a function in Java to display the prime numbers between 0 and 100, but the function should also take into consideration a list of excluded prime numbers that should not be displayed. | codefeedback |
Develop a program to spell a given word using only vowels.
"Hello" | codefeedback |
Construct a switch statement for the given pseudo-code to determine the type of day based on the given day of the week.
1. Initialize a variable "day" with the given day of the week.
2. Use a switch statement with "day" as the expression.
3. Inside the switch statement, add cases for each day of the week (Sunday to Sat... | codefeedback |
Build a web scraper in Python to fetch the restaurant details from the website.
<uri of the website>
However, the website has implemented anti-scraping measures such as IP blocking and CAPTCHA. Your task is to find a way to bypass these measures and successfully scrape the restaurant details. | codefeedback |
Write a program that takes a string as input and prints it 7 times, each time with an increasing number of exclamation marks at the end. For example, if the input string is "hello", the program should print:
hello
hello!
hello!!
hello!!!
hello!!!!
hello!!!!!
hello!!!!!!
hello!!!!!!!
Note: You are not allowed to use a... | codefeedback |
Determine the longest word in a given string, but exclude any words that contain the letter "e".
sentence = "I am Python Programmer" | codefeedback |
Given a number n, print “Hello” n times, each time with a delay of 1 second between each print statement.
n = 5 | codefeedback |
Iterate over a list and count the number of occurrences of each item, without using built-in functions.
Additional requirement: The solution should have a time complexity of O(n). | codefeedback |
Write a Python program to remove the nth index character from a nonempty string. The program should also handle cases where the given index is out of range. The program should return the modified string as well as the total number of characters removed. Additionally, the program should prompt the user to enter the stri... | codefeedback |
Get all permutations of a string.
string = "abc"
# Erroneous Code #
```python
def get_permutations(string):
if len(string) <= 1:
return [string]
permutations = []
for i in range(len(string)):
for perm in get_permutations(string[:i] + string[i+1:]):
permutations.append(strin... | codefeedback |
Create a JS program that rotates a given string by a random number of characters between 3 and 10. | codefeedback |
Create a function that reverses a given string without using the built-in reverse method or the use of any additional data structures.
str = 'I am here for the coding challenge' | codefeedback |
Modify the following code so that it takes a string as a parameter, reverses it and prints out the reversed string. Additionally, the solution should be implemented using recursion instead of iteration. The input string will always be alphanumeric and can have a maximum length of 100 characters. | codefeedback |
Implement a function that calculates the power of a number without using the built-in power operator or any multiplication operator.
Signature:
def calculate_power(base: int, exponent: int) -> int:
Example:
calculate_power(3, 4) -> 81 | codefeedback |
Find a way to get the size of a linked list without traversing it. Additionally, the linked list can contain duplicate values.
head: 1 -> 2 -> 3 -> 4 -> 2 -> 5 -> null | codefeedback |
Identify the possible output types for the following task.
Task: Write a Spark program to calculate the mean, median, and mode of a set of numbers. Additionally, the program should identify any outliers within the dataset. | codefeedback |
Write a function to find the smallest subarray with a given sum.
The input to the function is an array of positive integers and a target sum. The function should return the length of the smallest subarray in the input array that has a sum greater than or equal to the target sum. If no such subarray exists, the functio... | codefeedback |
Rewrite this code into Python, but ensure that the sum is calculated only for even numbers in the ArrayList. The final sum should be printed out as the result. | codefeedback |
Write a SQL query to find the number of customers that have purchased a product more than 5 times, and have a positive balance. The database has four tables:
customer(cust_id, cust_name, balance)
product(prod_id, prod_name, price)
sales(cust_id, prod_id, quantity)
category(cat_id, cat_name)
Note: The category table h... | codefeedback |
Create a Java class for representing a student object that includes the following:
- The student object should have a unique identifier.
- The student object should have a first name and last name.
- The student object should have an age.
- The student object should have a list of courses they are enrolled in.
- The st... | codefeedback |
Explain the purpose and importance of a classifier model in machine learning, and provide an example of a real-world application where a classifier model is used. | codefeedback |
Build a package and deploy it in the cloud. The package is an API to authenticate users and the API should be able to authenticate users having different types of API keys. The API should also include functionality for user registration and password recovery. Additionally, the API must be able to handle concurrent requ... | codefeedback |
Compare and contrast the fundamental concepts and principles of object-oriented programming (OOP) and procedural programming. Additionally, discuss the advantages and disadvantages of each approach in terms of code organization, reusability, and maintainability. Finally, provide examples of real-world scenarios where O... | codefeedback |
Generate all combinations of the string "abcd" where each combination contains exactly 3 characters. | codefeedback |
Create a function that takes in two strings and determines if the strings are anagrams, but with the additional constraint that the function must be case-insensitive. | codefeedback |
Create a program to split the given string on a specific character and return the resulting list. Additionally, if the character appears multiple times consecutively, treat it as a single delimiter and exclude empty strings from the resulting list. Implement the splitting logic without using any built-in string splitti... | codefeedback |
Write a program that generates a bar chart representing the total sales of a company in different months. The program should allow the user to input the number of months and the corresponding total sales for each month. The program should then display the bar chart using HTML.
Example:
Input:
Number of months: 6
Total... | codefeedback |
Create a JavaScript object that holds the global temperatures for the last 10 years, with each year having temperatures for all 12 months. The temperatures should be randomly generated between a range of -50 to 50 degrees Celsius. | codefeedback |
Write an R function to calculate the binomial coefficient of n and k using a recursive approach. | codefeedback |
Compile the following code in C++ and check for any warnings or errors. The program should also display the message "Hello World!" 10 times, with a delay of 1 second between each display. | codefeedback |
Create a Java program to print out the multiplication table for the first 100 prime numbers. | codefeedback |
Change the code to make it an Expression Statement in Python that evaluates the sum of all prime numbers between 1 and 1000. | codefeedback |
Write a Python function that takes a list of integers as input and returns the largest and smallest numbers in the list. | codefeedback |
Create a function to output true if the given string is a palindrome, otherwise output false.
string = "racecar"
Additional Requirements:
- The function should have a time complexity of O(n), where n is the length of the string.
- The function should not use any built-in string reversal functions or methods.
- The fu... | codefeedback |
Find the number of different words in a string of unlimited length, while also considering case sensitivity and punctuation marks.
# Explanation #
In this test, you need to count the number of unique words in a given string. However, unlike the previous test, you also need to consider case sensitivity and punctuation ... | codefeedback |
Create an HTML webpage which when opened displays the current date and time in a paragraph, updating every second. Additionally, the webpage should have a button that, when clicked, stops the updating of the date and time display. | codefeedback |
Increase the difficulty of the given programming test question by adding more reasoning steps and making the task more complex.
#Updated Test#
Modify the code to make it a valid Python program by following these steps:
1. Declare a variable named `x` and assign the string value "hello world" to it.
2. Add a line of co... | codefeedback |
Write a SQL query to find the top 3 highest paying employee’s name, salary, and department. The salary should be greater than $100,000 and the department should not be "Finance". | codefeedback |
Create a function that takes in an array of strings and outputs an array of tuples of the first and last word in each string. The function should ignore any leading or trailing whitespace in each string. The input array can contain up to 100 strings and each string can have up to 100 characters. The function should ret... | codefeedback |
Create a dictionary where the numbers 1 to 100 are the keys and the strings "one" to "one hundred" are the values. However, for all numbers divisible by 3, the value should be "Fizz", for all numbers divisible by 5, the value should be "Buzz", and for all numbers divisible by both 3 and 5, the value should be "FizzBuzz... | codefeedback |
Write a query in SQL that returns all customers with the name "John" and have made at least 5 purchases. | codefeedback |
Create an asyncio event loop and execute a coroutine that performs a CPU-intensive task. The coroutine should accept a list of integers as input and return a list containing the prime numbers from the input list. The event loop should run until the coroutine is complete, and the final result should be printed. | codefeedback |
Create a Java program to compute the volume of a cube, but instead of directly asking for the side length of the cube as input, ask the user for the diameter of a sphere that is inscribed in the cube. Then, calculate the side length of the cube using the given diameter and finally compute the volume of the cube. | codefeedback |
Use a framework like React to create a button component that fires an event when clicked. Additionally, implement a feature where the button changes its color randomly every time it is clicked. | codefeedback |
Compute the sum of all elements in a numpy array, but exclude any elements that are divisible by 2. The array must have at least 2 rows and 3 columns. You are required to use the numpy library for this task.
import numpy as np
arr = np.array([[1,2,3],[4,5,6]]) | codefeedback |
Create a function in Python that takes two integers N and M and prints out all possible combinations of numbers that add up to N and are at most M. Additionally, implement a check to ensure that each combination is unique.
For example, given N=8 and M=3, the function should print out the following combinations:
1+1+1+... | codefeedback |
Convert an array of tuples of 2 numbers into an array of complex numbers, while also sorting the resulting array based on the magnitude of the complex numbers in descending order.
tuple_array = [(3,4), (5,6), (7,8)] | codefeedback |
Create an instance of an Apache Spark DataFrame using an existing Pandas dataframe and perform the following transformations and actions on the DataFrame:
1. Apply a logarithmic transformation on column 'A' and store the result in a new column called 'log_A'.
2. Filter out rows where the value in column 'B' is less th... | codefeedback |
Given a list of emails and corresponding info, write a code to keep only the emails and transform the list into a dictionary of emails and corresponding info. Each email must be validated to ensure it is in the correct format of [username]@[domain].[extension]. The dictionary should also include the length of each emai... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.