instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a Python program to iterate through the given list and print the square root of each element, but only if the element is a prime number between 2 and 10. If the element is not a prime number or is outside the range, print "Invalid number: {element}". If the element is greater than or equal to 10, stop iterating. ... | codefeedback |
Design a class hierarchy for a library system. The library system should have a collection of books, which can be checked out by library patrons. Each book should have a title, author, and publication year. The library patrons should have a name, age, and a unique ID number.
The library system should have the followi... | codefeedback |
Given an array of integers, find the index of the element that appears an odd number of times. The array will contain at most 10^6 elements and each element will be an integer between 1 and 10^9 (inclusive). The time complexity of your solution should be O(n) and the space complexity should be O(1).
Additionally, the ... | codefeedback |
Given a large text document, create a dictionary that contains the count of the top k most frequent words. The program should be efficient and able to handle large amounts of text data. You are not allowed to use any built-in functions or libraries for counting words or sorting. The program should have a time complexit... | codefeedback |
How can you create a copy of a list while also reversing the order of its elements, without using any built-in list methods or functions? | codefeedback |
Implement the Quick Sort algorithm with a list of numbers. The numbers in the list can be negative and can range from -1000 to 1000. The list can contain duplicates.
The implementation should be able to handle lists with up to 1 million elements efficiently.
Additionally, the implementation should handle the scenario... | codefeedback |
Given a list of integers and the length n, write a Python program to add the elements of all even indexed values to the corresponding odd indexed values.
The program should also find the maximum sum of elements that can be obtained by selecting non-consecutive elements from the list.
The program should have a time c... | codefeedback |
Write a function that converts a list of strings to a dictionary, but with the following additional requirements:
1. The function should handle duplicate keys in the list gracefully. If a duplicate key is encountered, the function should combine the corresponding values into a list and store it in the dictionary.
2. ... | codefeedback |
Write a Python program to compare two strings and return True if both the strings are equal, otherwise False. The program should also handle case sensitivity, so "Hello" and "hello" should be considered different strings. Additionally, the program should ignore leading and trailing white spaces in the strings when comp... | codefeedback |
Write a Python program to find all the equilibrium indexes of an array. An index of an array is called equilibrium index if the sum of elements at lower indexes (excluding the element at the index itself) is equal to the sum of elements at higher indexes (excluding the element at the index itself). The program should r... | codefeedback |
Create a function that takes in a dictionary and returns a data frame. Each row in the data frame should represent the population data for a specific state and year combination. The dictionary should have the following structure:
my_dict = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada'],
'year': [2000,... | codefeedback |
Write a program that takes in an input list and generates a random permutation of the given list. The program should also ensure that no two consecutive elements in the permutation are the same.
For example, given the input list [1, 2, 3, 4, 5], a possible output could be [2, 3, 5, 1, 4].
To solve this problem, you ... | codefeedback |
Create a function that returns the nth Fibonacci number, but using a recursive approach with memoization to optimize performance. Additionally, handle negative input values by raising an exception with a custom error message. | codefeedback |
Create an algorithm to convert a temperature from Celsius to Fahrenheit, considering that the input temperature can be in any real number format and the output should be rounded to the nearest integer. Additionally, the algorithm should also check if the input temperature is within a valid range and handle any invalid ... | codefeedback |
Write a function to classify the input based on the following criteria:
If the input is a prime number and a Fibonacci number, output "prime Fibonacci"; if the input is a prime number and a palindrome, output "prime palindrome"; if the input is a perfect square and a palindrome, output "square palindrome"; if the inpu... | codefeedback |
Given a two-dimensional array, write a Python program to find the maximum sum of any subarray within the array that starts and ends at specified indices.
Example:
```python
my_array = [[1, -2, 3],
[4, -5, 6],
[7, -8, 9]]
start_row = 0
end_row = 1
start_col = 1
end_col = 2
```
Output:
5 (from ... | codefeedback |
Implement a sequence to sequence model for translation. Additionally, ensure that the model is trained using a large dataset with multiple language pairs and has a mechanism to handle out-of-vocabulary words during inference. The model should also include a mechanism for handling long sequences and should be optimized ... | codefeedback |
Write a function that takes in a 2D matrix and outputs the transpose of the matrix. The input matrix will have dimensions m x n, where m and n are positive integers. The function should return a new matrix with dimensions n x m, where the rows and columns of the input matrix are swapped. The elements in the new matrix ... | codefeedback |
Create a function that takes an array of strings and returns an array of their lengths. Each string in the array should be at least 7 characters long and no more than 20 characters long. The function should ignore any strings that contain numbers or special characters, but also ignore strings that start with a vowel. R... | codefeedback |
Write an SQL query to select the customer names with an age of 25 or more, ordered by their total purchase amount in descending order. Additionally, only include customers who have made at least 5 purchases and have a total purchase amount greater than $500. | codefeedback |
Create a JavaScript function to merge two given arrays, where one array contains numbers and the other array contains strings. The merged array should alternate between numbers and strings in the same order as they appear in the original arrays. Additionally, the merged array should also include objects from a third ar... | codefeedback |
Generate a SHA-256 hash for a given dictionary, ensuring that all keys and values are in lowercase and the keys are sorted alphabetically. The dictionary should not contain any empty or null values. Only consider keys and values that are of string or integer type. Return the hash in hexadecimal format.
To increase the... | codefeedback |
Write an efficient algorithm in Python to determine if an array has duplicate elements or not. Your algorithm should have a time complexity of O(n log n) and a space complexity of O(n). Additionally, the array can contain integer elements ranging from 1 to 10^6. | codefeedback |
Perform PCA on a dataset and implement it from scratch without using any built-in functions or libraries for matrix operations. Additionally, you are not allowed to use any loops or iterative operations in your implementation. | codefeedback |
Implement a function in Python to determine if a string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity. The function should also ignore any spaces, special characters, and punctuation marks. The time complexity of your solution should be O(n). Additionally, the function should b... | codefeedback |
Write a program that takes an array of integers as input and returns the maximum sum of a subarray within the array. The subarray must consist of consecutive elements from the original array.
For example, given the input array [1, -3, 2, 1, -1], the program should return 3, which is the maximum sum of the subarray [2,... | codefeedback |
Edit the following Java code to print the elements of a two-dimensional array in the form of a matrix, where each element is surrounded by parentheses and separated by a comma. However, you are not allowed to use any loops, built-in methods, or recursion in your solution. Additionally, the code should only work for arr... | codefeedback |
Generate a Python function that takes 'string' as an argument and return a new string with the last two characters of 'string' repeated. The input string will always have at least two characters and at most 100 characters. Additionally, the function should handle cases where the input string contains special characters... | codefeedback |
Write a Python function that generates a dictionary with the keys 'a', 'b', 'c' and values '1', '2', '3' respectively. Additionally, the function should check if the given values are integers and raise an exception if they are not. However, the function should also check if the given values are prime numbers and raise ... | codefeedback |
Construct an if/else statement that checks if a number is between 1 and 10, divisible by 2, and not a multiple of 3. | codefeedback |
Modify the given code to include a try/except statement. Additionally, add a piece of erroneous code that will cause an exception to be raised. Your program should handle the exception and display an appropriate error message. Ensure that the program handles all possible exceptions that could be raised. | codefeedback |
Construct a for loop to iterate over the following JSON data. Each iteration should print out the name and age of each person in the data in the format "Name: [name], Age: [age]". However, for the person with the highest age, the age should be printed out in Roman numerals instead of Arabic numerals. Additionally, for ... | codefeedback |
Write a Python function to split a string into a list of strings, separated by a given delimiter. The function should have a time complexity of O(n), where n is the length of the input string. Additionally, the function should handle nested delimiters, where a nested delimiter is defined as a delimiter that is enclosed... | codefeedback |
Create a function that returns true if the number is divisible by 5 and the sum of its digits is also divisible by 3. If the input is not a number or a negative number, return False. | codefeedback |
Create a JavaScript function that converts a given number to an array of its prime factors. Additionally, the function should handle input validation and error handling. | codefeedback |
Implement a function for generating a list of Fibonacci numbers up to n, with a time complexity of O(log n).
In addition, the function should handle negative input values and return an empty list if the input is negative.
You should also handle cases where n is a float or a string representation of a number. In such ... | codefeedback |
Implement a sorting algorithm to sort a list of integers in descending order. Your algorithm should have a time complexity of O(n log n) or better. You are not allowed to use any built-in sorting functions or libraries. Additionally, your algorithm should be space efficient and use constant extra space, i.e., it should... | codefeedback |
Create a code snippet for making a POST request to a RESTful API using Python. Additionally, include error handling for common HTTP errors such as 400 Bad Request, 401 Unauthorized, 404 Not Found, and 500 Internal Server Error. Ensure that the code handles exceptions properly and provides appropriate error messages for... | codefeedback |
Write a code to sort an array of integers using the quicksort algorithm. The algorithm should be implemented recursively. Additionally, the code should handle duplicate elements in the array and sort them in ascending order. The sorted array should be returned as the output. The code should have a time complexity of O(... | codefeedback |
Write a program that determines the data type of the following string: '2947'. The program should only use built-in functions and not rely on any external libraries or packages.
Additionally, the program should also check if the given string can be converted to any other data types, such as integer, float, or boolean.... | codefeedback |
Design a class for an Employee with attributes name, experience, salary, and a list of projects they have worked on.
The Employee class should have the following methods:
1. `add_project(project_name: str, duration: int, role: str)` - This method should add a new project to the employee's list of projects. The projec... | codefeedback |
Design a data structure to find the first and last occurrence of a prime number in an array of positive integers. The array may contain duplicates and the data structure should efficiently handle multiple queries. Additionally, the data structure should support adding and removing elements from the array while maintain... | codefeedback |
Create a new array in JavaScript given an existing one and a number, but make sure that the new array does not contain any duplicate elements and is sorted in descending order. | codefeedback |
Explain the differences between a function and a method in Java, and provide examples to illustrate these differences. Additionally, discuss the concept of method overloading in Java and how it relates to functions and methods. Finally, provide an implementation of a class in Java that showcases the use of method overl... | codefeedback |
Design a distributed system for an online pharmacy that can handle a large number of concurrent users and has high availability. Additionally, the system should be able to handle international shipping and implement a rewards program for loyal customers.
- The system should have multiple servers distributed across dif... | codefeedback |
Write a SQL query to identify the employees whose salary is greater than $50k, have been working for at least 5 years, and are also not part of the management team. | codefeedback |
Use regex to match a substring, 'the' within a sentence but only if it is followed by the word 'quick' and preceded by a word that starts with a capital letter. Additionally, the sentence should not contain any other occurrence of 'the' except for the one that satisfies the given conditions. | codefeedback |
## Updated Test ##
Create a function that takes in an array of integers and returns a list of all the elements that appear exactly once in the array. The function should exclude any duplicates or elements that appear more than once.
Additionally, the function should handle the following cases:
1. The input array can... | codefeedback |
Create a CSS style that displays a bold, centered header with the text "Hello World!" and a background color of blue. Additionally, add a hover effect that changes the background color to red when the user hovers over the header. The header should also have a border radius of 10px and a shadow effect. | codefeedback |
Develop an algorithm to calculate the length of a string, but the algorithm must be written in a functional programming language like Haskell or Scala. Additionally, the algorithm must not use any built-in functions or libraries for string manipulation. | codefeedback |
Write C++ code to implement a stack data structure with the following additional requirements:
1. The stack should have a maximum capacity, specified by the user, and should not allow pushing elements beyond this capacity.
2. The stack should also have a minimum capacity, specified by the user, and should not allow po... | codefeedback |
Edit the given HTML structure to add a container element with the class name "container". Ensure that the container element is positioned at the center of the page both vertically and horizontally, regardless of the screen size or resolution. Additionally, make sure that the container element is always visible on the s... | codefeedback |
Compare the bottom-up merge sort algorithm and the quicksort algorithm using Hoare's partition scheme in terms of their time complexity, space complexity, stability, and average case performance. Explain the reasoning behind your comparisons and provide an implementation for both algorithms. | codefeedback |
Create a function that takes in an integer x and returns True if x is a prime number and False otherwise. | codefeedback |
Create a CSS style to set a border on all sides of the element, with the following additional requirements:
1. The border color should change to red when the element is hovered over.
2. The border should be a solid line.
3. The width of the border should be 5 pixels.
4. The border should have a padding of 15 pixels on ... | codefeedback |
Write a SQL query to calculate the sum of the column "Price" from the table "Products" for a specific category. Additionally, only include products with a price higher than the average price of all products in the same category. You are not allowed to use any aggregate functions or subqueries in your solution. | codefeedback |
Write a JavaScript function that takes an array of color codes as input and sets the background color of each element to the respective color code. Additionally, change the text color to white for each element.
Example input: ["#ffa11f", "#00ff00", "#0000ff"]
Note:
- The function should modify the DOM to change the b... | codefeedback |
Explain static and dynamic dispatch in C++, and provide an example code demonstrating their usage. Discuss the advantages and disadvantages of each dispatch method in terms of performance, flexibility, and code maintainability. Also, provide a comparison between the two dispatch methods in terms of their impact on soft... | codefeedback |
Implement a shell sort algorithm in Python that sorts an array of integers in ascending order.
Requirements:
- The time complexity of your solution should be O(n^2).
- You are not allowed to use any built-in sorting functions or libraries.
- Your implementation should be in-place, i.e., it should not create a new arra... | codefeedback |
Create a function to check if a string contains only unique characters without using any additional data structures. The function should have a time complexity of O(n^2) and should not use any built-in library functions. The string will only contain lowercase alphabets. Additionally, the function should return the coun... | codefeedback |
Write a SQL query that counts the number of customers by country, orders the result by the number of customers in descending order, and includes only countries with more than 2 customers in the result. | codefeedback |
Using the given code, add the missing terminating condition for the loop. Ensure that the loop stops iterating when the sum of all the values in the 'values' list exceeds | codefeedback |
Write a Python program to inverse a dictionary, so that the keys become values and values become keys. The dictionary may contain duplicate values. Your program should handle duplicate values by storing them in a list as the corresponding keys.
Example:
Input:
dictionary = {1:'Apple', 2:'Orange', 3:'Banana', 4:'Appl... | codefeedback |
What is the hexadecimal representation of the number 255? Convert the number to hexadecimal using bitwise operations only. Your solution should be implemented using a recursive algorithm and should have a time complexity of O(log n), where n is the number being converted. | codefeedback |
Create a Java program to print a square diamond pattern with '*' characters. However, the program should only print the diamond pattern if the input number is prime and falls within the range of 1 to 1000. Additionally, the program should also include a method to check if a given number is a perfect square and only pri... | codefeedback |
Write a C program that takes an integer as input and prints the sum of all its digits. The program should handle negative numbers and ignore any non-digit characters present in the input. Additionally, the program should calculate the sum using a recursive function rather than a loop. The input number will be within th... | codefeedback |
Write a function in Python that takes in two lists of integers and returns the lengths of the lists, the values that are common in both lists, and the count of common values. Additionally, the function should raise a ValueError if either of the input lists contains duplicate values.
#Example:
Input:
list1 = [1, 2, 3,... | codefeedback |
Create a JavaScript function for sorting an array of numbers in ascending order using the merge sort algorithm. The time complexity of the sorting function should be O(n log n) and the space complexity should be O(n). Do not use any built-in sorting functions or libraries. Additionally, you are not allowed to use any r... | codefeedback |
Edit the following code in Python to swap the first and last elements in a list, while also reversing the order of the elements in between.
list1 = [1, 2, 3, 4, 5]
list1[0], list1[-1] = list1[-1], list1[0]
list1[1:-1] = list1[-2:0:-1] | codefeedback |
Tokenize the given sentence using regular expressions. Sentence: He likes the quick brown fox. Only include words that start with a capital letter. In addition, remove any punctuation marks that might be present in the sentence before tokenizing. | codefeedback |
Write a SQL statement to select all rows in a table and order them in descending order based on a specific column. However, the specific column should be determined dynamically at runtime based on user input. | codefeedback |
Convert the string in the given variable to lowercase and remove any special characters. Additionally, count the number of vowels and consonants separately in the resulting string. Also, display the frequency of each vowel and consonant in the string.
String: "HELLO WORLD!!!" | codefeedback |
Write a SQL query to find all books in the library with the title "Harry Potter" that were published in the last 5 years. The query should also display the number of copies available for each book and sort the results in descending order of the number of copies. | codefeedback |
Create a function in JavaScript to check if a given number is a prime number. The function should also return the next prime number if the given number is not prime. | codefeedback |
Create an object with key-value pairs using JavaScript and ensure that all keys are unique, all values are of type string, and all values are in uppercase. | codefeedback |
Explain how a Depth-First-Search (DFS) algorithm works, and provide a step-by-step explanation of how the algorithm traverses a graph. Additionally, discuss the time and space complexity of the DFS algorithm and provide examples of real-life scenarios where DFS can be applied effectively.
For the programming part of t... | codefeedback |
Parse the given string of JSON data and validate that the "name" field is not empty and the "age" field is a positive integer. Additionally, ensure that the "email" field is a valid email address and the "address" field is a non-empty string. "{ "name": "John", "age": 20, "email": "john@example.com", "address": "123 Ma... | codefeedback |
Generate a list with the numbers from 1 to 10 in reverse order using Python. Your solution must use a recursive function. | codefeedback |
Create a JavaScript function that takes an array of numbers as parameter and returns the second smallest prime number in it.
## Requirements ##
1. The input array may contain positive or negative integers.
2. The function should handle non-numeric elements in the array by ignoring them.
3. If the input array contains ... | codefeedback |
Write a SQL statement to select customers who have placed an order within the last 7 days and have also made at least 5 previous orders in the past 6 months. | codefeedback |
Write a JavaScript program to find out the day of the week for a given date, taking into account the Julian calendar system. However, you cannot use any built-in date/time functions or libraries in your solution.
Provide a piece of erroneous code as a reference to increase misdirection. | codefeedback |
Reverse a linked list of integers and output the result. The input will be provided as a head node of the linked list.
Additional Information:
1. The linked list node is defined as follows:
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
2. The inp... | codefeedback |
Create a Python class "Point" that has two instance variables x and y. Implement a method called "distance_to_origin" that calculates the distance between the point and the origin (0,0) using the Pythagorean theorem. Additionally, the class should have a method called "translate" that takes in two parameters dx and dy ... | codefeedback |
Generate an SQL statement to select the top 10 most expensive items from a table named "products" that were sold between a specific date range and have a quantity sold greater than 100. | codefeedback |
Merge the elements of two given arrays into one, while maintaining the order of the elements in each array. The resulting array should have all the elements from the first array followed by all the elements from the second array. You should not use any built-in functions or libraries for merging the arrays.
For exampl... | codefeedback |
Create a custom function to use in a python program that checks whether a given number is a prime number. However, the function should have a time complexity of O(sqrt(n)), where n is the given number. | codefeedback |
Given a string variable, write a function to convert it to uppercase without using any built-in string manipulation functions or methods in JavaScript. Additionally, the function should handle special characters and maintain their positions in the converted string. | codefeedback |
Construct a query using Mongoose that returns all documents that match a certain criteria, but only if the "age" field is greater than or equal to 30 and the "name" field starts with the letter "J". Find all documents in the "users" collection where the "city" field is equal to "Los Angeles". Additionally, sort the res... | codefeedback |
Write a JavaScript function that dynamically creates a button element with the following requirements:
1. The button should have a unique ID generated randomly.
2. The button should have a class named "custom-button".
3. The button text should be "Click Me".
4. When the button is clicked, it should trigger an alert wi... | codefeedback |
Create an array of 1 million elements using Java and initialize each element with a unique value. The unique values should be randomly generated within a specified range. | codefeedback |
Design a function to convert a given numerical grade to a corresponding letter grade, but with the following additional requirements:
- The function should only accept numerical grades within the range of 0 to 100 (inclusive).
- The function should handle both integer and floating-point input grades.
- The function sho... | codefeedback |
Write a query in elasticsearch that returns documents that contain matching content. Find all documents in the "products" index that contains the phrase "Black Friday" and have a minimum price of $100. Additionally, sort the results in descending order based on the number of sales and limit the results to 10. | codefeedback |
Convert a JSON string to an XML string with the following conditions:
1. Preserve the hierarchy of the JSON data in the XML.
2. Convert JSON key-value pairs to XML elements and attributes.
3. Handle nested JSON objects and arrays appropriately in the XML structure.
4. Use specific XML tags for different data types, suc... | codefeedback |
Devise a programming logic to find the sum of the first 1000 prime numbers that are palindromic primes. | codefeedback |
Write a function in Python to merge two sorted arrays in descending order, but you are not allowed to use any built-in sorting functions or methods.
arr1 = [9, 5, 1]
arr2 = [8, 6, 3, 2] | codefeedback |
Devise a logic using PHP to check if a number is prime. Additionally, the solution should not use any built-in PHP functions for prime number checking. Provide a piece of erroneous code that attempts to check for prime numbers but contains logical errors. | codefeedback |
Generate a correct C++ class definition to fulfill the following tasks with higher difficulty.
Create a class that has four member variables: a, b, c and d.
The variable a should be of type integer, b should be of type float, c should be of type string and d should be of type boolean.
Additionally, the class should hav... | codefeedback |
Implement a function in Pandas that handles missing data by interpolating the missing values based on the values of neighboring data points. The function should have a time complexity of O(n) and should be able to handle datasets with up to 1 million rows. Additionally, the function should handle cases where the missin... | codefeedback |
Explain what a hash table is and provide a working implementation in a programming language of your choice. Additionally, demonstrate how collisions are handled in your implementation and explain the impact of different collision resolution methods on the performance of the hash table. | codefeedback |
Explain what is the critical section on a process and discuss why it is important in concurrent programming. Additionally, provide an example scenario where the concept of critical section is applied and discuss how it can be effectively managed to prevent race conditions. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.